summaryrefslogtreecommitdiff
path: root/src/mscorlib
diff options
context:
space:
mode:
authorJiyoung Yun <jy910.yun@samsung.com>2016-12-27 16:46:08 +0900
committerJiyoung Yun <jy910.yun@samsung.com>2016-12-27 16:46:08 +0900
commitdb20f3f1bb8595633a7e16c8900fd401a453a6b5 (patch)
treee5435159cd1bf0519276363a6fe1663d1721bed3 /src/mscorlib
parent4b4aad7217d3292650e77eec2cf4c198ea9c3b4b (diff)
downloadcoreclr-db20f3f1bb8595633a7e16c8900fd401a453a6b5.tar.gz
coreclr-db20f3f1bb8595633a7e16c8900fd401a453a6b5.tar.bz2
coreclr-db20f3f1bb8595633a7e16c8900fd401a453a6b5.zip
Imported Upstream version 1.0.0.9127upstream/1.0.0.9127
Diffstat (limited to 'src/mscorlib')
-rw-r--r--src/mscorlib/Common/PinnableBufferCache.cs97
-rw-r--r--src/mscorlib/System.Private.CoreLib.csproj4
-rw-r--r--src/mscorlib/System.Private.CoreLib.sln5
-rw-r--r--src/mscorlib/corefx/Debug.cs29
-rw-r--r--src/mscorlib/corefx/Interop/Unix/Interop.Errors.cs207
-rw-r--r--src/mscorlib/corefx/Interop/Unix/Interop.IOErrors.cs170
-rw-r--r--src/mscorlib/corefx/Interop/Unix/Interop.Libraries.cs7
-rw-r--r--src/mscorlib/corefx/Interop/Unix/System.Globalization.Native/Interop.Collation.cs5
-rw-r--r--src/mscorlib/corefx/Interop/Unix/System.Globalization.Native/Interop.Idna.cs21
-rw-r--r--src/mscorlib/corefx/Interop/Unix/System.Globalization.Native/Interop.Locale.cs3
-rw-r--r--src/mscorlib/corefx/Interop/Unix/System.Globalization.Native/Interop.Normalization.cs19
-rw-r--r--src/mscorlib/corefx/Interop/Unix/System.Globalization.Native/Interop.ResultCode.cs1
-rw-r--r--src/mscorlib/corefx/Interop/Unix/System.Native/Interop.Close.cs15
-rw-r--r--src/mscorlib/corefx/Interop/Unix/System.Native/Interop.FLock.cs31
-rw-r--r--src/mscorlib/corefx/Interop/Unix/System.Native/Interop.FSync.cs15
-rw-r--r--src/mscorlib/corefx/Interop/Unix/System.Native/Interop.FTruncate.cs15
-rw-r--r--src/mscorlib/corefx/Interop/Unix/System.Native/Interop.Fcntl.cs21
-rw-r--r--src/mscorlib/corefx/Interop/Unix/System.Native/Interop.GetCwd.cs74
-rw-r--r--src/mscorlib/corefx/Interop/Unix/System.Native/Interop.GetUnixName.cs21
-rw-r--r--src/mscorlib/corefx/Interop/Unix/System.Native/Interop.LSeek.cs22
-rw-r--r--src/mscorlib/corefx/Interop/Unix/System.Native/Interop.MksTemps.cs17
-rw-r--r--src/mscorlib/corefx/Interop/Unix/System.Native/Interop.Open.cs15
-rw-r--r--src/mscorlib/corefx/Interop/Unix/System.Native/Interop.OpenFlags.cs27
-rw-r--r--src/mscorlib/corefx/Interop/Unix/System.Native/Interop.PathConf.cs73
-rw-r--r--src/mscorlib/corefx/Interop/Unix/System.Native/Interop.Permissions.cs32
-rw-r--r--src/mscorlib/corefx/Interop/Unix/System.Native/Interop.PosixFAdvise.cs36
-rw-r--r--src/mscorlib/corefx/Interop/Unix/System.Native/Interop.Read.cs25
-rw-r--r--src/mscorlib/corefx/Interop/Unix/System.Native/Interop.Stat.cs59
-rw-r--r--src/mscorlib/corefx/Interop/Unix/System.Native/Interop.Unlink.cs15
-rw-r--r--src/mscorlib/corefx/Interop/Unix/System.Native/Interop.Write.cs27
-rw-r--r--src/mscorlib/corefx/Interop/Windows/BCrypt/Interop.BCryptGenRandom.cs26
-rw-r--r--src/mscorlib/corefx/Interop/Windows/BCrypt/Interop.NTSTATUS.cs19
-rw-r--r--src/mscorlib/corefx/Interop/Windows/Crypt32/Interop.CryptProtectMemory.cs22
-rw-r--r--src/mscorlib/corefx/Interop/Windows/Interop.BOOL.cs21
-rw-r--r--src/mscorlib/corefx/Interop/Windows/Interop.Libraries.cs82
-rw-r--r--src/mscorlib/corefx/Interop/Windows/NtDll/Interop.ZeroMemory.cs19
-rw-r--r--src/mscorlib/corefx/Interop/Windows/mincore/Interop.CancelIoEx.cs16
-rw-r--r--src/mscorlib/corefx/Interop/Windows/mincore/Interop.CloseHandle.cs16
-rw-r--r--src/mscorlib/corefx/Interop/Windows/mincore/Interop.CreateFile.cs40
-rw-r--r--src/mscorlib/corefx/Interop/Windows/mincore/Interop.Errors.cs74
-rw-r--r--src/mscorlib/corefx/Interop/Windows/mincore/Interop.FileOperations.cs35
-rw-r--r--src/mscorlib/corefx/Interop/Windows/mincore/Interop.FileTypes.cs16
-rw-r--r--src/mscorlib/corefx/Interop/Windows/mincore/Interop.FlushFileBuffers.cs17
-rw-r--r--src/mscorlib/corefx/Interop/Windows/mincore/Interop.FormatMessage.cs112
-rw-r--r--src/mscorlib/corefx/Interop/Windows/mincore/Interop.GetFileInformationByHandleEx.cs26
-rw-r--r--src/mscorlib/corefx/Interop/Windows/mincore/Interop.GetFileType_SafeHandle.cs15
-rw-r--r--src/mscorlib/corefx/Interop/Windows/mincore/Interop.GetFullPathNameW.cs18
-rw-r--r--src/mscorlib/corefx/Interop/Windows/mincore/Interop.GetLongPathNameW.cs18
-rw-r--r--src/mscorlib/corefx/Interop/Windows/mincore/Interop.GetTempFileNameW.cs16
-rw-r--r--src/mscorlib/corefx/Interop/Windows/mincore/Interop.GetTempPathW.cs16
-rw-r--r--src/mscorlib/corefx/Interop/Windows/mincore/Interop.Idna.cs37
-rw-r--r--src/mscorlib/corefx/Interop/Windows/mincore/Interop.LockFile.cs20
-rw-r--r--src/mscorlib/corefx/Interop/Windows/mincore/Interop.ReadFile_SafeHandle_IntPtr.cs21
-rw-r--r--src/mscorlib/corefx/Interop/Windows/mincore/Interop.ReadFile_SafeHandle_NativeOverlapped.cs22
-rw-r--r--src/mscorlib/corefx/Interop/Windows/mincore/Interop.SECURITY_ATTRIBUTES.cs21
-rw-r--r--src/mscorlib/corefx/Interop/Windows/mincore/Interop.SafeCreateFile.cs45
-rw-r--r--src/mscorlib/corefx/Interop/Windows/mincore/Interop.SecurityOptions.cs18
-rw-r--r--src/mscorlib/corefx/Interop/Windows/mincore/Interop.SetEndOfFile.cs15
-rw-r--r--src/mscorlib/corefx/Interop/Windows/mincore/Interop.SetErrorMode.cs14
-rw-r--r--src/mscorlib/corefx/Interop/Windows/mincore/Interop.SetFileInformationByHandle.cs72
-rw-r--r--src/mscorlib/corefx/Interop/Windows/mincore/Interop.SetFilePointerEx.cs15
-rw-r--r--src/mscorlib/corefx/Interop/Windows/mincore/Interop.ThreadPoolIO.cs27
-rw-r--r--src/mscorlib/corefx/Interop/Windows/mincore/Interop.UnsafeCreateFile.cs25
-rw-r--r--src/mscorlib/corefx/Interop/Windows/mincore/Interop.WideCharToMultiByte.cs22
-rw-r--r--src/mscorlib/corefx/Interop/Windows/mincore/Interop.WriteFile_SafeHandle_IntPtr.cs24
-rw-r--r--src/mscorlib/corefx/Interop/Windows/mincore/Interop.WriteFile_SafeHandle_NativeOverlapped.cs22
-rw-r--r--src/mscorlib/corefx/Interop/Windows/oleaut32/Interop.SysAllocStringLen.cs16
-rw-r--r--src/mscorlib/corefx/Interop/Windows/oleaut32/Interop.SysStringLen.cs22
-rw-r--r--src/mscorlib/corefx/Microsoft/Win32/SafeHandles/SafeFileHandle.Unix.cs122
-rw-r--r--src/mscorlib/corefx/Microsoft/Win32/SafeHandles/SafeFileHandle.Windows.cs50
-rw-r--r--src/mscorlib/corefx/Microsoft/Win32/SafeHandles/SafeThreadPoolIOHandle.cs28
-rw-r--r--src/mscorlib/corefx/SR.cs823
-rw-r--r--src/mscorlib/corefx/System/Buffers/ArrayPool.cs113
-rw-r--r--src/mscorlib/corefx/System/Buffers/ArrayPoolEventSource.cs78
-rw-r--r--src/mscorlib/corefx/System/Buffers/ConfigurableArrayPool.cs265
-rw-r--r--src/mscorlib/corefx/System/Buffers/TlsOverPerCoreLockedStacksArrayPool.Unix.cs28
-rw-r--r--src/mscorlib/corefx/System/Buffers/TlsOverPerCoreLockedStacksArrayPool.Windows.cs20
-rw-r--r--src/mscorlib/corefx/System/Buffers/TlsOverPerCoreLockedStacksArrayPool.cs328
-rw-r--r--src/mscorlib/corefx/System/Buffers/Utilities.cs35
-rw-r--r--src/mscorlib/corefx/System/Globalization/Calendar.cs42
-rw-r--r--src/mscorlib/corefx/System/Globalization/CalendarAlgorithmType.cs20
-rw-r--r--src/mscorlib/corefx/System/Globalization/CalendarData.Unix.cs3
-rw-r--r--src/mscorlib/corefx/System/Globalization/CalendarData.cs8
-rw-r--r--src/mscorlib/corefx/System/Globalization/CalendricalCalculationsHelper.cs31
-rw-r--r--src/mscorlib/corefx/System/Globalization/CharUnicodeInfo.cs110
-rw-r--r--src/mscorlib/corefx/System/Globalization/CharUnicodeInfoData.cs25
-rw-r--r--src/mscorlib/corefx/System/Globalization/ChineseLunisolarCalendar.cs4
-rw-r--r--src/mscorlib/corefx/System/Globalization/CompareInfo.Unix.cs140
-rw-r--r--src/mscorlib/corefx/System/Globalization/CompareInfo.Windows.cs78
-rw-r--r--src/mscorlib/corefx/System/Globalization/CompareInfo.cs283
-rw-r--r--src/mscorlib/corefx/System/Globalization/CultureData.Unix.cs164
-rw-r--r--src/mscorlib/corefx/System/Globalization/CultureData.Windows.cs132
-rw-r--r--src/mscorlib/corefx/System/Globalization/CultureData.cs392
-rw-r--r--src/mscorlib/corefx/System/Globalization/CultureInfo.Windows.cs6
-rw-r--r--src/mscorlib/corefx/System/Globalization/CultureInfo.cs528
-rw-r--r--src/mscorlib/corefx/System/Globalization/CultureNotFoundException.cs35
-rw-r--r--src/mscorlib/corefx/System/Globalization/CultureTypes.cs28
-rw-r--r--src/mscorlib/corefx/System/Globalization/DateTimeFormatInfo.cs343
-rw-r--r--src/mscorlib/corefx/System/Globalization/DayLightTime.cs49
-rw-r--r--src/mscorlib/corefx/System/Globalization/DigitShapes.cs17
-rw-r--r--src/mscorlib/corefx/System/Globalization/EastAsianLunisolarCalendar.cs41
-rw-r--r--src/mscorlib/corefx/System/Globalization/GregorianCalendar.cs57
-rw-r--r--src/mscorlib/corefx/System/Globalization/GregorianCalendarHelper.cs24
-rw-r--r--src/mscorlib/corefx/System/Globalization/HebrewCalendar.cs43
-rw-r--r--src/mscorlib/corefx/System/Globalization/HebrewNumber.cs11
-rw-r--r--src/mscorlib/corefx/System/Globalization/HijriCalendar.Win32.cs86
-rw-r--r--src/mscorlib/corefx/System/Globalization/HijriCalendar.WinRT.cs (renamed from src/mscorlib/corefx/System/Globalization/HijriCalendar.Windows.cs)2
-rw-r--r--src/mscorlib/corefx/System/Globalization/HijriCalendar.cs31
-rw-r--r--src/mscorlib/corefx/System/Globalization/IdnMapping.Unix.cs134
-rw-r--r--src/mscorlib/corefx/System/Globalization/IdnMapping.Windows.cs113
-rw-r--r--src/mscorlib/corefx/System/Globalization/IdnMapping.cs152
-rw-r--r--src/mscorlib/corefx/System/Globalization/JapaneseCalendar.Unix.cs3
-rw-r--r--src/mscorlib/corefx/System/Globalization/JapaneseCalendar.Win32.cs209
-rw-r--r--src/mscorlib/corefx/System/Globalization/JapaneseCalendar.WinRT.cs (renamed from src/mscorlib/corefx/System/Globalization/JapaneseCalendar.Windows.cs)0
-rw-r--r--src/mscorlib/corefx/System/Globalization/JapaneseCalendar.cs18
-rw-r--r--src/mscorlib/corefx/System/Globalization/JulianCalendar.cs37
-rw-r--r--src/mscorlib/corefx/System/Globalization/KoreanCalendar.cs11
-rw-r--r--src/mscorlib/corefx/System/Globalization/KoreanLunisolarCalendar.cs4
-rw-r--r--src/mscorlib/corefx/System/Globalization/LocaleData.Unix.cs4572
-rw-r--r--src/mscorlib/corefx/System/Globalization/NumberFormatInfo.cs91
-rw-r--r--src/mscorlib/corefx/System/Globalization/PersianCalendar.cs54
-rw-r--r--src/mscorlib/corefx/System/Globalization/RegionInfo.cs117
-rw-r--r--src/mscorlib/corefx/System/Globalization/STUBS.cs180
-rw-r--r--src/mscorlib/corefx/System/Globalization/SortKey.cs209
-rw-r--r--src/mscorlib/corefx/System/Globalization/SortVersion.cs101
-rw-r--r--src/mscorlib/corefx/System/Globalization/StringInfo.cs89
-rw-r--r--src/mscorlib/corefx/System/Globalization/TaiwanCalendar.cs13
-rw-r--r--src/mscorlib/corefx/System/Globalization/TextElementEnumerator.cs10
-rw-r--r--src/mscorlib/corefx/System/Globalization/TextInfo.Unix.cs5
-rw-r--r--src/mscorlib/corefx/System/Globalization/TextInfo.Windows.cs6
-rw-r--r--src/mscorlib/corefx/System/Globalization/TextInfo.cs324
-rw-r--r--src/mscorlib/corefx/System/Globalization/ThaiBuddhistCalendar.cs11
-rw-r--r--src/mscorlib/corefx/System/Globalization/UmAlQuraCalendar.cs40
-rw-r--r--src/mscorlib/corefx/System/HResults.cs236
-rw-r--r--src/mscorlib/corefx/System/IO/Error.cs44
-rw-r--r--src/mscorlib/corefx/System/IO/FileStream.NetStandard17.cs76
-rw-r--r--src/mscorlib/corefx/System/IO/FileStream.Unix.cs934
-rw-r--r--src/mscorlib/corefx/System/IO/FileStream.Win32.cs1770
-rw-r--r--src/mscorlib/corefx/System/IO/FileStream.cs654
-rw-r--r--src/mscorlib/corefx/System/IO/FileStreamCompletionSource.Win32.cs221
-rw-r--r--src/mscorlib/corefx/System/IO/Path.Unix.cs256
-rw-r--r--src/mscorlib/corefx/System/IO/Path.Win32.cs36
-rw-r--r--src/mscorlib/corefx/System/IO/Path.Windows.cs153
-rw-r--r--src/mscorlib/corefx/System/IO/Path.cs578
-rw-r--r--src/mscorlib/corefx/System/IO/PathHelper.Windows.cs (renamed from src/mscorlib/src/System/IO/LongPathHelper.cs)204
-rw-r--r--src/mscorlib/corefx/System/IO/PathInternal.CaseSensitivity.cs75
-rw-r--r--src/mscorlib/corefx/System/IO/PathInternal.Unix.cs122
-rw-r--r--src/mscorlib/corefx/System/IO/PathInternal.Windows.StringBuffer.cs89
-rw-r--r--src/mscorlib/corefx/System/IO/PathInternal.Windows.cs482
-rw-r--r--src/mscorlib/corefx/System/IO/PathInternal.cs230
-rw-r--r--src/mscorlib/corefx/System/IO/Win32Marshal.cs134
-rw-r--r--src/mscorlib/corefx/System/Runtime/InteropServices/NativeBuffer.cs (renamed from src/mscorlib/src/System/Runtime/InteropServices/NativeBuffer.cs)34
-rw-r--r--src/mscorlib/corefx/System/Runtime/InteropServices/SafeHeapHandle.cs (renamed from src/mscorlib/src/System/Runtime/InteropServices/SafeHeapHandle.cs)14
-rw-r--r--src/mscorlib/corefx/System/Runtime/InteropServices/SafeHeapHandleCache.cs97
-rw-r--r--src/mscorlib/corefx/System/Runtime/InteropServices/StringBuffer.cs (renamed from src/mscorlib/src/System/Runtime/InteropServices/StringBuffer.cs)110
-rw-r--r--src/mscorlib/corefx/System/Security/CryptographicException.cs44
-rw-r--r--src/mscorlib/corefx/System/Security/SafeBSTRHandle.cs81
-rw-r--r--src/mscorlib/corefx/System/Security/SecureString.Unix.cs295
-rw-r--r--src/mscorlib/corefx/System/Security/SecureString.Windows.cs310
-rw-r--r--src/mscorlib/corefx/System/Security/SecureString.cs189
-rw-r--r--src/mscorlib/corefx/System/Threading/ClrThreadPoolBoundHandle.cs319
-rw-r--r--src/mscorlib/corefx/System/Threading/ClrThreadPoolBoundHandleOverlapped.cs52
-rw-r--r--src/mscorlib/corefx/System/Threading/ClrThreadPoolPreAllocatedOverlapped.cs105
-rw-r--r--src/mscorlib/corefx/System/Threading/DeferredDisposableLifetime.cs116
-rw-r--r--src/mscorlib/facade/TypeForwards.cs37
-rw-r--r--src/mscorlib/facade/mscorlib.csproj37
-rw-r--r--src/mscorlib/facade/project.json1
-rw-r--r--src/mscorlib/model.xml1110
-rw-r--r--src/mscorlib/mscorlib.shared.sources.props220
-rw-r--r--src/mscorlib/ref/mscorlib.cs839
-rw-r--r--src/mscorlib/src/Internal/Runtime/Augments/EnvironmentAugments.cs7
-rw-r--r--src/mscorlib/src/Internal/Runtime/Augments/RuntimeThread.cs198
-rw-r--r--src/mscorlib/src/Microsoft/Win32/OAVariantLib.cs6
-rw-r--r--src/mscorlib/src/Microsoft/Win32/Registry.cs24
-rw-r--r--src/mscorlib/src/Microsoft/Win32/RegistryKey.cs296
-rw-r--r--src/mscorlib/src/Microsoft/Win32/SafeHandles/SafeFileHandle.cs43
-rw-r--r--src/mscorlib/src/Microsoft/Win32/SafeHandles/SafeFileMappingHandle.cs4
-rw-r--r--src/mscorlib/src/Microsoft/Win32/SafeHandles/SafeFindHandle.cs3
-rw-r--r--src/mscorlib/src/Microsoft/Win32/SafeHandles/SafeLibraryHandle.cs12
-rw-r--r--src/mscorlib/src/Microsoft/Win32/SafeHandles/SafeLocalAllocHandle.cs6
-rw-r--r--src/mscorlib/src/Microsoft/Win32/SafeHandles/SafeRegistryHandle.cs4
-rw-r--r--src/mscorlib/src/Microsoft/Win32/SafeHandles/SafeViewOfFileHandle.cs4
-rw-r--r--src/mscorlib/src/Microsoft/Win32/SafeHandles/SafeWaitHandle.cs2
-rw-r--r--src/mscorlib/src/Microsoft/Win32/SafeHandles/Win32SafeHandles.cs25
-rw-r--r--src/mscorlib/src/Microsoft/Win32/UnsafeNativeMethods.cs8
-rw-r--r--src/mscorlib/src/Microsoft/Win32/Win32Native.cs115
-rw-r--r--src/mscorlib/src/System.Private.CoreLib.txt1251
-rw-r--r--src/mscorlib/src/System/Action.cs43
-rw-r--r--src/mscorlib/src/System/Activator.cs136
-rw-r--r--src/mscorlib/src/System/AggregateException.cs17
-rw-r--r--src/mscorlib/src/System/AppContext/AppContext.cs56
-rw-r--r--src/mscorlib/src/System/AppContext/AppContextDefaultValues.Defaults.cs12
-rw-r--r--src/mscorlib/src/System/AppContext/AppContextDefaultValues.cs6
-rw-r--r--src/mscorlib/src/System/AppContext/AppContextSwitches.cs30
-rw-r--r--src/mscorlib/src/System/AppDomain.cs2188
-rw-r--r--src/mscorlib/src/System/AppDomainManager.cs171
-rw-r--r--src/mscorlib/src/System/AppDomainSetup.cs469
-rw-r--r--src/mscorlib/src/System/ApplicationId.cs6
-rw-r--r--src/mscorlib/src/System/ArgIterator.cs11
-rw-r--r--src/mscorlib/src/System/ArgumentException.cs3
-rw-r--r--src/mscorlib/src/System/ArgumentNullException.cs1
-rw-r--r--src/mscorlib/src/System/ArgumentOutOfRangeException.cs3
-rw-r--r--src/mscorlib/src/System/Array.cs433
-rw-r--r--src/mscorlib/src/System/ArraySegment.cs96
-rw-r--r--src/mscorlib/src/System/Attribute.cs137
-rw-r--r--src/mscorlib/src/System/BCLDebug.cs32
-rw-r--r--src/mscorlib/src/System/BadImageFormatException.cs3
-rw-r--r--src/mscorlib/src/System/BitConverter.cs61
-rw-r--r--src/mscorlib/src/System/Boolean.cs2
-rw-r--r--src/mscorlib/src/System/Buffer.cs50
-rw-r--r--src/mscorlib/src/System/ByReference.cs31
-rw-r--r--src/mscorlib/src/System/Byte.cs4
-rw-r--r--src/mscorlib/src/System/CLRConfig.cs2
-rw-r--r--src/mscorlib/src/System/CfgParser.cs14
-rw-r--r--src/mscorlib/src/System/Char.cs94
-rw-r--r--src/mscorlib/src/System/Collections/ArrayList.cs179
-rw-r--r--src/mscorlib/src/System/Collections/BitArray.cs524
-rw-r--r--src/mscorlib/src/System/Collections/CollectionBase.cs10
-rw-r--r--src/mscorlib/src/System/Collections/Comparer.cs5
-rw-r--r--src/mscorlib/src/System/Collections/CompatibleComparer.cs2
-rw-r--r--src/mscorlib/src/System/Collections/Concurrent/ConcurrentDictionary.cs216
-rw-r--r--src/mscorlib/src/System/Collections/Concurrent/ConcurrentQueue.cs21
-rw-r--r--src/mscorlib/src/System/Collections/Concurrent/ConcurrentStack.cs91
-rw-r--r--src/mscorlib/src/System/Collections/Concurrent/IProducerConsumerCollection.cs2
-rw-r--r--src/mscorlib/src/System/Collections/Concurrent/OrderablePartitioner.cs1
-rw-r--r--src/mscorlib/src/System/Collections/Concurrent/Partitioner.cs1
-rw-r--r--src/mscorlib/src/System/Collections/Concurrent/PartitionerStatic.cs104
-rw-r--r--src/mscorlib/src/System/Collections/DictionaryEntry.cs7
-rw-r--r--src/mscorlib/src/System/Collections/EmptyReadOnlyDictionaryInternal.cs20
-rw-r--r--src/mscorlib/src/System/Collections/Generic/ArraySortHelper.cs452
-rw-r--r--src/mscorlib/src/System/Collections/Generic/Comparer.cs18
-rw-r--r--src/mscorlib/src/System/Collections/Generic/DebugView.cs2
-rw-r--r--src/mscorlib/src/System/Collections/Generic/Dictionary.cs101
-rw-r--r--src/mscorlib/src/System/Collections/Generic/EqualityComparer.cs171
-rw-r--r--src/mscorlib/src/System/Collections/Generic/KeyValuePair.cs17
-rw-r--r--src/mscorlib/src/System/Collections/Generic/List.cs116
-rw-r--r--src/mscorlib/src/System/Collections/Hashtable.cs187
-rw-r--r--src/mscorlib/src/System/Collections/ListDictionaryInternal.cs30
-rw-r--r--src/mscorlib/src/System/Collections/ObjectModel/Collection.cs8
-rw-r--r--src/mscorlib/src/System/Collections/ObjectModel/KeyedCollection.cs4
-rw-r--r--src/mscorlib/src/System/Collections/ObjectModel/ReadOnlyCollection.cs8
-rw-r--r--src/mscorlib/src/System/Collections/ObjectModel/ReadOnlyDictionary.cs14
-rw-r--r--src/mscorlib/src/System/Collections/SortedList.cs39
-rw-r--r--src/mscorlib/src/System/Collections/Stack.cs13
-rw-r--r--src/mscorlib/src/System/CompatibilitySwitches.cs72
-rw-r--r--src/mscorlib/src/System/ContextBoundObject.cs24
-rw-r--r--src/mscorlib/src/System/ContextStaticAttribute.cs32
-rw-r--r--src/mscorlib/src/System/Convert.cs80
-rw-r--r--src/mscorlib/src/System/Currency.cs2
-rw-r--r--src/mscorlib/src/System/CurrentTimeZone.cs276
-rw-r--r--src/mscorlib/src/System/DBNull.cs1
-rw-r--r--src/mscorlib/src/System/DateTime.cs86
-rw-r--r--src/mscorlib/src/System/DateTimeOffset.cs34
-rw-r--r--src/mscorlib/src/System/Decimal.cs60
-rw-r--r--src/mscorlib/src/System/DefaultBinder.cs26
-rw-r--r--src/mscorlib/src/System/Delegate.cs107
-rw-r--r--src/mscorlib/src/System/DelegateSerializationHolder.cs29
-rw-r--r--src/mscorlib/src/System/Diagnostics/Assert.cs18
-rw-r--r--src/mscorlib/src/System/Diagnostics/AssertFilter.cs1
-rw-r--r--src/mscorlib/src/System/Diagnostics/Contracts/Contracts.cs19
-rw-r--r--src/mscorlib/src/System/Diagnostics/Contracts/ContractsBCL.cs62
-rw-r--r--src/mscorlib/src/System/Diagnostics/Debugger.cs9
-rw-r--r--src/mscorlib/src/System/Diagnostics/DebuggerAttributes.cs20
-rw-r--r--src/mscorlib/src/System/Diagnostics/Eventing/ActivityTracker.cs13
-rw-r--r--src/mscorlib/src/System/Diagnostics/Eventing/EventProvider.cs66
-rw-r--r--src/mscorlib/src/System/Diagnostics/Eventing/EventSource.cs465
-rw-r--r--src/mscorlib/src/System/Diagnostics/Eventing/EventSource_CoreCLR.cs4
-rw-r--r--src/mscorlib/src/System/Diagnostics/Eventing/TraceLogging/DataCollector.cs1
-rw-r--r--src/mscorlib/src/System/Diagnostics/Eventing/TraceLogging/EventPayload.cs9
-rw-r--r--src/mscorlib/src/System/Diagnostics/Eventing/TraceLogging/EventSourceActivity.cs2
-rw-r--r--src/mscorlib/src/System/Diagnostics/Eventing/TraceLogging/FieldMetadata.cs2
-rw-r--r--src/mscorlib/src/System/Diagnostics/Eventing/TraceLogging/PropertyValue.cs7
-rw-r--r--src/mscorlib/src/System/Diagnostics/Eventing/TraceLogging/SimpleTypeInfos.cs3
-rw-r--r--src/mscorlib/src/System/Diagnostics/Eventing/TraceLogging/Statics.cs2
-rw-r--r--src/mscorlib/src/System/Diagnostics/Eventing/TraceLogging/TraceLoggingDataCollector.cs1
-rw-r--r--src/mscorlib/src/System/Diagnostics/Eventing/TraceLogging/TraceLoggingEventSource.cs18
-rw-r--r--src/mscorlib/src/System/Diagnostics/Eventing/TraceLogging/TraceLoggingEventTypes.cs10
-rw-r--r--src/mscorlib/src/System/Diagnostics/Eventing/TraceLogging/TraceLoggingMetadataCollector.cs6
-rw-r--r--src/mscorlib/src/System/Diagnostics/Eventing/TraceLogging/TraceLoggingTypeInfo.cs4
-rw-r--r--src/mscorlib/src/System/Diagnostics/Eventing/XplatEventLogger.cs28
-rw-r--r--src/mscorlib/src/System/Diagnostics/LogSwitch.cs7
-rw-r--r--src/mscorlib/src/System/Diagnostics/Stackframe.cs23
-rw-r--r--src/mscorlib/src/System/Diagnostics/Stacktrace.cs79
-rw-r--r--src/mscorlib/src/System/Diagnostics/SymbolStore/ISymWriter.cs30
-rw-r--r--src/mscorlib/src/System/Diagnostics/log.cs5
-rw-r--r--src/mscorlib/src/System/Double.cs8
-rw-r--r--src/mscorlib/src/System/Empty.cs3
-rw-r--r--src/mscorlib/src/System/Enum.cs174
-rw-r--r--src/mscorlib/src/System/Environment.cs1154
-rw-r--r--src/mscorlib/src/System/Exception.cs88
-rw-r--r--src/mscorlib/src/System/FormattableString.cs2
-rw-r--r--src/mscorlib/src/System/GC.cs172
-rw-r--r--src/mscorlib/src/System/Globalization/Calendar.cs18
-rw-r--r--src/mscorlib/src/System/Globalization/CalendarData.cs6
-rw-r--r--src/mscorlib/src/System/Globalization/CalendricalCalculationsHelper.cs17
-rw-r--r--src/mscorlib/src/System/Globalization/CharUnicodeInfo.cs66
-rw-r--r--src/mscorlib/src/System/Globalization/ChineseLunisolarCalendar.cs4
-rw-r--r--src/mscorlib/src/System/Globalization/CompareInfo.cs171
-rw-r--r--src/mscorlib/src/System/Globalization/CultureData.cs445
-rw-r--r--src/mscorlib/src/System/Globalization/CultureInfo.cs167
-rw-r--r--src/mscorlib/src/System/Globalization/CultureNotFoundException.cs3
-rw-r--r--src/mscorlib/src/System/Globalization/DateTimeFormat.cs134
-rw-r--r--src/mscorlib/src/System/Globalization/DateTimeFormatInfo.cs248
-rw-r--r--src/mscorlib/src/System/Globalization/DateTimeFormatInfoScanner.cs3
-rw-r--r--src/mscorlib/src/System/Globalization/DateTimeParse.cs90
-rw-r--r--src/mscorlib/src/System/Globalization/DaylightTime.cs23
-rw-r--r--src/mscorlib/src/System/Globalization/EastAsianLunisolarCalendar.cs26
-rw-r--r--src/mscorlib/src/System/Globalization/EncodingDataItem.cs7
-rw-r--r--src/mscorlib/src/System/Globalization/EncodingTable.Unix.cs9
-rw-r--r--src/mscorlib/src/System/Globalization/EncodingTable.cs16
-rw-r--r--src/mscorlib/src/System/Globalization/GlobalizationAssembly.cs8
-rw-r--r--src/mscorlib/src/System/Globalization/GregorianCalendar.cs50
-rw-r--r--src/mscorlib/src/System/Globalization/GregorianCalendarHelper.cs24
-rw-r--r--src/mscorlib/src/System/Globalization/HebrewCalendar.cs31
-rw-r--r--src/mscorlib/src/System/Globalization/HebrewNumber.cs3
-rw-r--r--src/mscorlib/src/System/Globalization/HijriCalendar.cs24
-rw-r--r--src/mscorlib/src/System/Globalization/IdnMapping.cs156
-rw-r--r--src/mscorlib/src/System/Globalization/JapaneseCalendar.cs5
-rw-r--r--src/mscorlib/src/System/Globalization/JulianCalendar.cs18
-rw-r--r--src/mscorlib/src/System/Globalization/KoreanCalendar.cs2
-rw-r--r--src/mscorlib/src/System/Globalization/KoreanLunisolarCalendar.cs4
-rw-r--r--src/mscorlib/src/System/Globalization/NumberFormatInfo.cs66
-rw-r--r--src/mscorlib/src/System/Globalization/PersianCalendar.cs37
-rw-r--r--src/mscorlib/src/System/Globalization/RegionInfo.cs200
-rw-r--r--src/mscorlib/src/System/Globalization/SortKey.cs7
-rw-r--r--src/mscorlib/src/System/Globalization/StringInfo.cs29
-rw-r--r--src/mscorlib/src/System/Globalization/TaiwanCalendar.cs4
-rw-r--r--src/mscorlib/src/System/Globalization/TextElementEnumerator.cs7
-rw-r--r--src/mscorlib/src/System/Globalization/TextInfo.cs77
-rw-r--r--src/mscorlib/src/System/Globalization/ThaiBuddhistCalendar.cs2
-rw-r--r--src/mscorlib/src/System/Globalization/TimeSpanFormat.cs30
-rw-r--r--src/mscorlib/src/System/Globalization/TimeSpanParse.cs33
-rw-r--r--src/mscorlib/src/System/Globalization/UmAlQuraCalendar.cs31
-rw-r--r--src/mscorlib/src/System/Guid.cs37
-rw-r--r--src/mscorlib/src/System/IAppDomain.cs246
-rw-r--r--src/mscorlib/src/System/IAppDomainPauseManager.cs15
-rw-r--r--src/mscorlib/src/System/IO/BinaryReader.cs46
-rw-r--r--src/mscorlib/src/System/IO/BinaryWriter.cs37
-rw-r--r--src/mscorlib/src/System/IO/BufferedStream.cs1320
-rw-r--r--src/mscorlib/src/System/IO/Directory.cs642
-rw-r--r--src/mscorlib/src/System/IO/DirectoryInfo.cs265
-rw-r--r--src/mscorlib/src/System/IO/DriveInfo.cs281
-rw-r--r--src/mscorlib/src/System/IO/EncodingCache.cs (renamed from src/mscorlib/src/System/Runtime/CompilerServices/IsPinned.cs)8
-rw-r--r--src/mscorlib/src/System/IO/File.cs658
-rw-r--r--src/mscorlib/src/System/IO/FileAttributes.cs20
-rw-r--r--src/mscorlib/src/System/IO/FileInfo.cs207
-rw-r--r--src/mscorlib/src/System/IO/FileLoadException.cs14
-rw-r--r--src/mscorlib/src/System/IO/FileNotFoundException.cs11
-rw-r--r--src/mscorlib/src/System/IO/FileSecurityState.cs133
-rw-r--r--src/mscorlib/src/System/IO/FileSecurityStateAccess.cs32
-rw-r--r--src/mscorlib/src/System/IO/FileStream.cs2695
-rw-r--r--src/mscorlib/src/System/IO/FileSystemEnumerable.cs185
-rw-r--r--src/mscorlib/src/System/IO/FileSystemInfo.cs137
-rw-r--r--src/mscorlib/src/System/IO/MemoryStream.cs112
-rw-r--r--src/mscorlib/src/System/IO/Path.cs1435
-rw-r--r--src/mscorlib/src/System/IO/PathHelper.cs448
-rw-r--r--src/mscorlib/src/System/IO/PathInternal.cs806
-rw-r--r--src/mscorlib/src/System/IO/PinnedBufferMemoryStream.cs6
-rw-r--r--src/mscorlib/src/System/IO/Stream.cs144
-rw-r--r--src/mscorlib/src/System/IO/StreamHelpers.CopyValidation.cs46
-rw-r--r--src/mscorlib/src/System/IO/StreamReader.cs100
-rw-r--r--src/mscorlib/src/System/IO/StreamWriter.cs175
-rw-r--r--src/mscorlib/src/System/IO/StringReader.cs187
-rw-r--r--src/mscorlib/src/System/IO/StringWriter.cs196
-rw-r--r--src/mscorlib/src/System/IO/TextReader.cs36
-rw-r--r--src/mscorlib/src/System/IO/TextWriter.cs37
-rw-r--r--src/mscorlib/src/System/IO/UnmanagedMemoryAccessor.cs215
-rw-r--r--src/mscorlib/src/System/IO/UnmanagedMemoryStream.cs187
-rw-r--r--src/mscorlib/src/System/IO/UnmanagedMemoryStreamWrapper.cs9
-rw-r--r--src/mscorlib/src/System/IO/__DebugOutputTextWriter.cs76
-rw-r--r--src/mscorlib/src/System/IO/__Error.cs12
-rw-r--r--src/mscorlib/src/System/Int16.cs3
-rw-r--r--src/mscorlib/src/System/Int32.cs4
-rw-r--r--src/mscorlib/src/System/Int64.cs4
-rw-r--r--src/mscorlib/src/System/IntPtr.cs27
-rw-r--r--src/mscorlib/src/System/Internal.cs19
-rw-r--r--src/mscorlib/src/System/InvalidTimeZoneException.cs12
-rw-r--r--src/mscorlib/src/System/Lazy.cs23
-rw-r--r--src/mscorlib/src/System/LowLevelConsole.cs3
-rw-r--r--src/mscorlib/src/System/MarshalByRefObject.cs245
-rw-r--r--src/mscorlib/src/System/Math.cs191
-rw-r--r--src/mscorlib/src/System/MathF.cs253
-rw-r--r--src/mscorlib/src/System/MissingFieldException.cs1
-rw-r--r--src/mscorlib/src/System/MissingMemberException.cs5
-rw-r--r--src/mscorlib/src/System/MissingMethodException.cs1
-rw-r--r--src/mscorlib/src/System/MulticastDelegate.cs40
-rw-r--r--src/mscorlib/src/System/NotFiniteNumberException.cs3
-rw-r--r--src/mscorlib/src/System/Nullable.cs2
-rw-r--r--src/mscorlib/src/System/Number.cs191
-rw-r--r--src/mscorlib/src/System/Numerics/Hashing/HashHelpers.cs19
-rw-r--r--src/mscorlib/src/System/Object.cs48
-rw-r--r--src/mscorlib/src/System/ObjectDisposedException.cs1
-rw-r--r--src/mscorlib/src/System/OleAutBinder.cs21
-rw-r--r--src/mscorlib/src/System/OperatingSystem.cs7
-rw-r--r--src/mscorlib/src/System/ParseNumbers.cs8
-rw-r--r--src/mscorlib/src/System/Progress.cs4
-rw-r--r--src/mscorlib/src/System/Random.cs74
-rw-r--r--src/mscorlib/src/System/ReadOnlySpan.cs397
-rw-r--r--src/mscorlib/src/System/Reflection/Assembly.cs1048
-rw-r--r--src/mscorlib/src/System/Reflection/AssemblyAttributes.cs2
-rw-r--r--src/mscorlib/src/System/Reflection/AssemblyName.cs274
-rw-r--r--src/mscorlib/src/System/Reflection/Associates.cs9
-rw-r--r--src/mscorlib/src/System/Reflection/ComInterfaces.cs572
-rw-r--r--src/mscorlib/src/System/Reflection/ConstructorInfo.cs145
-rw-r--r--src/mscorlib/src/System/Reflection/CustomAttribute.cs168
-rw-r--r--src/mscorlib/src/System/Reflection/Emit/AQNBuilder.cs30
-rw-r--r--src/mscorlib/src/System/Reflection/Emit/AssemblyBuilder.cs1145
-rw-r--r--src/mscorlib/src/System/Reflection/Emit/AssemblyBuilderAccess.cs6
-rw-r--r--src/mscorlib/src/System/Reflection/Emit/AssemblyBuilderData.cs40
-rw-r--r--src/mscorlib/src/System/Reflection/Emit/ComInterfaces.cs173
-rw-r--r--src/mscorlib/src/System/Reflection/Emit/ConstructorBuilder.cs61
-rw-r--r--src/mscorlib/src/System/Reflection/Emit/CustomAttributeBuilder.cs143
-rw-r--r--src/mscorlib/src/System/Reflection/Emit/DynamicILGenerator.cs69
-rw-r--r--src/mscorlib/src/System/Reflection/Emit/DynamicMethod.cs224
-rw-r--r--src/mscorlib/src/System/Reflection/Emit/EnumBuilder.cs30
-rw-r--r--src/mscorlib/src/System/Reflection/Emit/EventBuilder.cs47
-rw-r--r--src/mscorlib/src/System/Reflection/Emit/FieldBuilder.cs54
-rw-r--r--src/mscorlib/src/System/Reflection/Emit/FlowControl.cs3
-rw-r--r--src/mscorlib/src/System/Reflection/Emit/GenericTypeParameterBuilder.cs3
-rw-r--r--src/mscorlib/src/System/Reflection/Emit/ILGenerator.cs111
-rw-r--r--src/mscorlib/src/System/Reflection/Emit/ISymWrapperCore.cs136
-rw-r--r--src/mscorlib/src/System/Reflection/Emit/LocalBuilder.cs22
-rw-r--r--src/mscorlib/src/System/Reflection/Emit/MethodBuilder.cs165
-rw-r--r--src/mscorlib/src/System/Reflection/Emit/ModuleBuilder.cs489
-rw-r--r--src/mscorlib/src/System/Reflection/Emit/ModuleBuilderData.cs6
-rw-r--r--src/mscorlib/src/System/Reflection/Emit/Opcode.cs118
-rw-r--r--src/mscorlib/src/System/Reflection/Emit/OpcodeType.cs3
-rw-r--r--src/mscorlib/src/System/Reflection/Emit/OperandType.cs3
-rw-r--r--src/mscorlib/src/System/Reflection/Emit/ParameterBuilder.cs35
-rw-r--r--src/mscorlib/src/System/Reflection/Emit/PropertyBuilder.cs49
-rw-r--r--src/mscorlib/src/System/Reflection/Emit/SignatureHelper.cs69
-rw-r--r--src/mscorlib/src/System/Reflection/Emit/SymbolMethod.cs1
-rw-r--r--src/mscorlib/src/System/Reflection/Emit/SymbolType.cs2
-rw-r--r--src/mscorlib/src/System/Reflection/Emit/TypeBuilder.cs324
-rw-r--r--src/mscorlib/src/System/Reflection/Emit/TypeBuilderInstantiation.cs4
-rw-r--r--src/mscorlib/src/System/Reflection/Emit/UnmanagedMarshal.cs1
-rw-r--r--src/mscorlib/src/System/Reflection/Emit/XXXOnTypeBuilderInstantiation.cs13
-rw-r--r--src/mscorlib/src/System/Reflection/EventInfo.cs55
-rw-r--r--src/mscorlib/src/System/Reflection/FieldInfo.cs98
-rw-r--r--src/mscorlib/src/System/Reflection/IntrospectionExtensions.cs23
-rw-r--r--src/mscorlib/src/System/Reflection/InvalidFilterCriteriaException.cs4
-rw-r--r--src/mscorlib/src/System/Reflection/LoaderAllocator.cs2
-rw-r--r--src/mscorlib/src/System/Reflection/MdConstant.cs1
-rw-r--r--src/mscorlib/src/System/Reflection/MdImport.cs55
-rw-r--r--src/mscorlib/src/System/Reflection/MemberInfo.cs31
-rw-r--r--src/mscorlib/src/System/Reflection/MemberInfoSerializationHolder.cs6
-rw-r--r--src/mscorlib/src/System/Reflection/Metadata/AssemblyExtensions.cs4
-rw-r--r--src/mscorlib/src/System/Reflection/MethodBase.cs50
-rw-r--r--src/mscorlib/src/System/Reflection/MethodBody.cs3
-rw-r--r--src/mscorlib/src/System/Reflection/MethodInfo.cs164
-rw-r--r--src/mscorlib/src/System/Reflection/Missing.cs3
-rw-r--r--src/mscorlib/src/System/Reflection/Module.cs158
-rw-r--r--src/mscorlib/src/System/Reflection/ParameterInfo.cs90
-rw-r--r--src/mscorlib/src/System/Reflection/Pointer.cs14
-rw-r--r--src/mscorlib/src/System/Reflection/PropertyInfo.cs51
-rw-r--r--src/mscorlib/src/System/Reflection/ReflectionContext.cs2
-rw-r--r--src/mscorlib/src/System/Reflection/ReflectionTypeLoadException.cs3
-rw-r--r--src/mscorlib/src/System/Reflection/RuntimeReflectionExtensions.cs4
-rw-r--r--src/mscorlib/src/System/Reflection/StrongNameKeyPair.cs115
-rw-r--r--src/mscorlib/src/System/Reflection/TargetException.cs4
-rw-r--r--src/mscorlib/src/System/Reflection/TargetInvocationException.cs4
-rw-r--r--src/mscorlib/src/System/Reflection/TargetParameterCountException.cs4
-rw-r--r--src/mscorlib/src/System/Reflection/TypeDelegator.cs5
-rw-r--r--src/mscorlib/src/System/Resources/FileBasedResourceGroveler.cs31
-rw-r--r--src/mscorlib/src/System/Resources/IResourceGroveler.cs5
-rw-r--r--src/mscorlib/src/System/Resources/LooselyLinkedResourceReference.cs10
-rw-r--r--src/mscorlib/src/System/Resources/ManifestBasedResourceGroveler.cs153
-rw-r--r--src/mscorlib/src/System/Resources/NeutralResourcesLanguageAttribute.cs4
-rw-r--r--src/mscorlib/src/System/Resources/ResourceFallbackManager.cs14
-rw-r--r--src/mscorlib/src/System/Resources/ResourceManager.cs306
-rw-r--r--src/mscorlib/src/System/Resources/ResourceReader.cs71
-rw-r--r--src/mscorlib/src/System/Resources/ResourceSet.cs21
-rw-r--r--src/mscorlib/src/System/Resources/RuntimeResourceSet.cs9
-rw-r--r--src/mscorlib/src/System/Resources/SatelliteContractVersionAttribute.cs2
-rw-r--r--src/mscorlib/src/System/Resources/__FastResourceComparer.cs14
-rw-r--r--src/mscorlib/src/System/RtType.cs861
-rw-r--r--src/mscorlib/src/System/Runtime/CompilerServices/AsyncMethodBuilder.cs58
-rw-r--r--src/mscorlib/src/System/Runtime/CompilerServices/CallingConvention.cs30
-rw-r--r--src/mscorlib/src/System/Runtime/CompilerServices/ConditionalWeakTable.cs905
-rw-r--r--src/mscorlib/src/System/Runtime/CompilerServices/DecimalConstantAttribute.cs7
-rw-r--r--src/mscorlib/src/System/Runtime/CompilerServices/FormattableStringFactory.cs4
-rw-r--r--src/mscorlib/src/System/Runtime/CompilerServices/HasCopySemanticsAttribute.cs14
-rw-r--r--src/mscorlib/src/System/Runtime/CompilerServices/IDispatchConstantAttribute.cs26
-rw-r--r--src/mscorlib/src/System/Runtime/CompilerServices/INotifyCompletion.cs1
-rw-r--r--src/mscorlib/src/System/Runtime/CompilerServices/IUnknownConstantAttribute.cs27
-rw-r--r--src/mscorlib/src/System/Runtime/CompilerServices/IsBoxed.cs11
-rw-r--r--src/mscorlib/src/System/Runtime/CompilerServices/IsByValue.cs11
-rw-r--r--src/mscorlib/src/System/Runtime/CompilerServices/IsConst.cs11
-rw-r--r--src/mscorlib/src/System/Runtime/CompilerServices/IsCopyConstructed.cs11
-rw-r--r--src/mscorlib/src/System/Runtime/CompilerServices/IsExplicitlyDereferenced.cs22
-rw-r--r--src/mscorlib/src/System/Runtime/CompilerServices/IsImplicitlyDereferenced.cs22
-rw-r--r--src/mscorlib/src/System/Runtime/CompilerServices/IsJitIntrinsic.cs12
-rw-r--r--src/mscorlib/src/System/Runtime/CompilerServices/IsLong.cs18
-rw-r--r--src/mscorlib/src/System/Runtime/CompilerServices/IsSignUnspecifiedByte.cs16
-rw-r--r--src/mscorlib/src/System/Runtime/CompilerServices/IsUdtReturn.cs11
-rw-r--r--src/mscorlib/src/System/Runtime/CompilerServices/NativeCppClassAttribute.cs16
-rw-r--r--src/mscorlib/src/System/Runtime/CompilerServices/RequiredAttributeAttribute.cs26
-rw-r--r--src/mscorlib/src/System/Runtime/CompilerServices/RuntimeHelpers.cs92
-rw-r--r--src/mscorlib/src/System/Runtime/CompilerServices/RuntimeWrappedException.cs3
-rw-r--r--src/mscorlib/src/System/Runtime/CompilerServices/ScopelessEnumAttribute.cs14
-rw-r--r--src/mscorlib/src/System/Runtime/CompilerServices/TaskAwaiter.cs23
-rw-r--r--src/mscorlib/src/System/Runtime/CompilerServices/TypeDependencyAttribute.cs2
-rw-r--r--src/mscorlib/src/System/Runtime/CompilerServices/TypeForwardedFromAttribute.cs2
-rw-r--r--src/mscorlib/src/System/Runtime/CompilerServices/TypeForwardedToAttribute.cs1
-rw-r--r--src/mscorlib/src/System/Runtime/CompilerServices/Unsafe.cs80
-rw-r--r--src/mscorlib/src/System/Runtime/CompilerServices/YieldAwaitable.cs6
-rw-r--r--src/mscorlib/src/System/Runtime/CompilerServices/jithelpers.cs52
-rw-r--r--src/mscorlib/src/System/Runtime/ExceptionServices/ExceptionNotification.cs41
-rw-r--r--src/mscorlib/src/System/Runtime/ExceptionServices/ExceptionServicesCommon.cs2
-rw-r--r--src/mscorlib/src/System/Runtime/GcSettings.cs7
-rw-r--r--src/mscorlib/src/System/Runtime/InteropServices/ArrayWithOffset.cs2
-rw-r--r--src/mscorlib/src/System/Runtime/InteropServices/Attributes.cs12
-rw-r--r--src/mscorlib/src/System/Runtime/InteropServices/BStrWrapper.cs8
-rw-r--r--src/mscorlib/src/System/Runtime/InteropServices/COMException.cs1
-rw-r--r--src/mscorlib/src/System/Runtime/InteropServices/ComEventsHelper.cs16
-rw-r--r--src/mscorlib/src/System/Runtime/InteropServices/ComEventsInfo.cs5
-rw-r--r--src/mscorlib/src/System/Runtime/InteropServices/ComEventsSink.cs9
-rw-r--r--src/mscorlib/src/System/Runtime/InteropServices/CriticalHandle.cs11
-rw-r--r--src/mscorlib/src/System/Runtime/InteropServices/CurrencyWrapper.cs2
-rw-r--r--src/mscorlib/src/System/Runtime/InteropServices/DispatchWrapper.cs4
-rw-r--r--src/mscorlib/src/System/Runtime/InteropServices/ErrorWrapper.cs6
-rw-r--r--src/mscorlib/src/System/Runtime/InteropServices/ExtensibleClassFactory.cs1
-rw-r--r--src/mscorlib/src/System/Runtime/InteropServices/ExternalException.cs2
-rw-r--r--src/mscorlib/src/System/Runtime/InteropServices/GcHandle.cs21
-rw-r--r--src/mscorlib/src/System/Runtime/InteropServices/ICustomQueryInterface.cs1
-rw-r--r--src/mscorlib/src/System/Runtime/InteropServices/IException.cs48
-rw-r--r--src/mscorlib/src/System/Runtime/InteropServices/IRegistrationServices.cs6
-rw-r--r--src/mscorlib/src/System/Runtime/InteropServices/Marshal.cs622
-rw-r--r--src/mscorlib/src/System/Runtime/InteropServices/NativeMethods.cs4
-rw-r--r--src/mscorlib/src/System/Runtime/InteropServices/NonPortable.cs34
-rw-r--r--src/mscorlib/src/System/Runtime/InteropServices/RegistrationServices.cs52
-rw-r--r--src/mscorlib/src/System/Runtime/InteropServices/RuntimeEnvironment.cs57
-rw-r--r--src/mscorlib/src/System/Runtime/InteropServices/SafeBuffer.cs28
-rw-r--r--src/mscorlib/src/System/Runtime/InteropServices/SafeHandle.cs13
-rw-r--r--src/mscorlib/src/System/Runtime/InteropServices/TCEAdapterGen/EventProviderWriter.cs67
-rw-r--r--src/mscorlib/src/System/Runtime/InteropServices/TCEAdapterGen/EventSinkHelperWriter.cs9
-rw-r--r--src/mscorlib/src/System/Runtime/InteropServices/TypeLibConverter.cs595
-rw-r--r--src/mscorlib/src/System/Runtime/InteropServices/Variant.cs1
-rw-r--r--src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/BindableVectorToCollectionAdapter.cs11
-rw-r--r--src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/BindableVectorToListAdapter.cs30
-rw-r--r--src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/CLRIPropertyValueImpl.cs8
-rw-r--r--src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/CLRIReferenceImpl.cs11
-rw-r--r--src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ConstantSplittableMap.cs4
-rw-r--r--src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/CustomPropertyImpl.cs6
-rw-r--r--src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/DictionaryKeyCollection.cs8
-rw-r--r--src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/DictionaryToMapAdapter.cs12
-rw-r--r--src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/DictionaryValueCollection.cs8
-rw-r--r--src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/EnumeratorToIteratorAdapter.cs7
-rw-r--r--src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IClosable.cs8
-rw-r--r--src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ICustomPropertyProvider.cs7
-rw-r--r--src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IMapViewToIReadOnlyDictionaryAdapter.cs29
-rw-r--r--src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IReadOnlyDictionaryToIMapViewAdapter.cs6
-rw-r--r--src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IReadOnlyListToIVectorViewAdapter.cs8
-rw-r--r--src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IRestrictedErrorInfo.cs2
-rw-r--r--src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IVectorViewToIReadOnlyListAdapter.cs8
-rw-r--r--src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IteratorToEnumeratorAdapter.cs19
-rw-r--r--src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ListToBindableVectorAdapter.cs15
-rw-r--r--src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ListToBindableVectorViewAdapter.cs4
-rw-r--r--src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ListToVectorAdapter.cs19
-rw-r--r--src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ManagedActivationFactory.cs5
-rw-r--r--src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/MapToCollectionAdapter.cs14
-rw-r--r--src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/MapToDictionaryAdapter.cs23
-rw-r--r--src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/MapViewToReadOnlyCollectionAdapter.cs4
-rw-r--r--src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/NativeMethods.cs7
-rw-r--r--src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/RuntimeClass.cs9
-rw-r--r--src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/VectorToCollectionAdapter.cs14
-rw-r--r--src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/VectorToListAdapter.cs24
-rw-r--r--src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/VectorViewToReadOnlyCollectionAdapter.cs4
-rw-r--r--src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/WindowsRuntimeBufferHelper.cs2
-rw-r--r--src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/WindowsRuntimeMarshal.cs52
-rw-r--r--src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/WindowsRuntimeMetadata.cs5
-rw-r--r--src/mscorlib/src/System/Runtime/Loader/AssemblyLoadContext.cs92
-rw-r--r--src/mscorlib/src/System/Runtime/MemoryFailPoint.cs16
-rw-r--r--src/mscorlib/src/System/Runtime/ProfileOptimization.cs4
-rw-r--r--src/mscorlib/src/System/Runtime/Reliability/CriticalFinalizerObject.cs6
-rw-r--r--src/mscorlib/src/System/Runtime/Remoting/ObjectHandle.cs42
-rw-r--r--src/mscorlib/src/System/Runtime/Serialization/FormatterConverter.cs34
-rw-r--r--src/mscorlib/src/System/Runtime/Serialization/FormatterServices.cs76
-rw-r--r--src/mscorlib/src/System/Runtime/Serialization/IObjectReference.cs1
-rw-r--r--src/mscorlib/src/System/Runtime/Serialization/ISerializable.cs1
-rw-r--r--src/mscorlib/src/System/Runtime/Serialization/ISerializationSurrogate.cs2
-rw-r--r--src/mscorlib/src/System/Runtime/Serialization/ISurrogateSelector.cs3
-rw-r--r--src/mscorlib/src/System/Runtime/Serialization/SafeSerializationManager.cs446
-rw-r--r--src/mscorlib/src/System/Runtime/Serialization/SerializationFieldInfo.cs36
-rw-r--r--src/mscorlib/src/System/Runtime/Serialization/SerializationInfo.cs98
-rw-r--r--src/mscorlib/src/System/Runtime/Serialization/SerializationInfoEnumerator.cs15
-rw-r--r--src/mscorlib/src/System/Runtime/Versioning/BinaryCompatibility.cs485
-rw-r--r--src/mscorlib/src/System/Runtime/Versioning/CompatibilitySwitch.cs5
-rw-r--r--src/mscorlib/src/System/Runtime/Versioning/ComponentGuaranteesAttribute.cs44
-rw-r--r--src/mscorlib/src/System/Runtime/Versioning/ResourceAttributes.cs237
-rw-r--r--src/mscorlib/src/System/Runtime/Versioning/TargetFrameworkAttribute.cs2
-rw-r--r--src/mscorlib/src/System/RuntimeHandles.cs273
-rw-r--r--src/mscorlib/src/System/SByte.cs3
-rw-r--r--src/mscorlib/src/System/Security/AccessControl/Enums.cs6
-rw-r--r--src/mscorlib/src/System/Security/Attributes.cs11
-rw-r--r--src/mscorlib/src/System/Security/BuiltInPermissionSets.cs103
-rw-r--r--src/mscorlib/src/System/Security/CodeAccessPermission.cs69
-rw-r--r--src/mscorlib/src/System/Security/CodeAccessSecurityEngine.cs468
-rw-r--r--src/mscorlib/src/System/Security/FrameSecurityDescriptor.cs31
-rw-r--r--src/mscorlib/src/System/Security/HostProtectionException.cs5
-rw-r--r--src/mscorlib/src/System/Security/HostSecurityManager.cs131
-rw-r--r--src/mscorlib/src/System/Security/IEvidenceFactory.cs15
-rw-r--r--src/mscorlib/src/System/Security/ISecurityEncodable.cs18
-rw-r--r--src/mscorlib/src/System/Security/ISecurityPolicyEncodable.cs17
-rw-r--r--src/mscorlib/src/System/Security/NamedPermissionSet.cs202
-rw-r--r--src/mscorlib/src/System/Security/PermissionListSet.cs29
-rw-r--r--src/mscorlib/src/System/Security/PermissionSet.cs1100
-rw-r--r--src/mscorlib/src/System/Security/PermissionSetEnumerator.cs14
-rw-r--r--src/mscorlib/src/System/Security/PermissionSetTriple.cs20
-rw-r--r--src/mscorlib/src/System/Security/PermissionToken.cs202
-rw-r--r--src/mscorlib/src/System/Security/Permissions/EnvironmentPermission.cs60
-rw-r--r--src/mscorlib/src/System/Security/Permissions/FileDialogPermission.cs33
-rw-r--r--src/mscorlib/src/System/Security/Permissions/FileIOPermission.cs304
-rw-r--r--src/mscorlib/src/System/Security/Permissions/GACIdentityPermission.cs16
-rw-r--r--src/mscorlib/src/System/Security/Permissions/HostProtectionPermission.cs34
-rw-r--r--src/mscorlib/src/System/Security/Permissions/IsolatedStorageFilePermission.cs13
-rw-r--r--src/mscorlib/src/System/Security/Permissions/IsolatedStoragePermission.cs91
-rw-r--r--src/mscorlib/src/System/Security/Permissions/PermissionAttributes.cs314
-rw-r--r--src/mscorlib/src/System/Security/Permissions/ReflectionPermission.cs39
-rw-r--r--src/mscorlib/src/System/Security/Permissions/RegistryPermission.cs131
-rw-r--r--src/mscorlib/src/System/Security/Permissions/SecurityPermission.cs96
-rw-r--r--src/mscorlib/src/System/Security/Permissions/SiteIdentityPermission.cs108
-rw-r--r--src/mscorlib/src/System/Security/Permissions/StrongNameIdentityPermission.cs90
-rw-r--r--src/mscorlib/src/System/Security/Permissions/StrongNamePublicKeyBlob.cs2
-rw-r--r--src/mscorlib/src/System/Security/Permissions/UIPermission.cs44
-rw-r--r--src/mscorlib/src/System/Security/Permissions/URLIdentityPermission.cs111
-rw-r--r--src/mscorlib/src/System/Security/Permissions/ZoneIdentityPermission.cs101
-rw-r--r--src/mscorlib/src/System/Security/Permissions/keycontainerpermission.cs72
-rw-r--r--src/mscorlib/src/System/Security/Policy/ApplicationTrust.cs573
-rw-r--r--src/mscorlib/src/System/Security/Policy/Evidence.cs1865
-rw-r--r--src/mscorlib/src/System/Security/Policy/EvidenceBase.cs31
-rw-r--r--src/mscorlib/src/System/Security/Policy/EvidenceTypeDescriptor.cs20
-rw-r--r--src/mscorlib/src/System/Security/Policy/IDelayEvaluatedEvidence.cs1
-rw-r--r--src/mscorlib/src/System/Security/Policy/PolicyStatement.cs302
-rw-r--r--src/mscorlib/src/System/Security/Policy/Site.cs29
-rw-r--r--src/mscorlib/src/System/Security/Policy/StrongName.cs59
-rw-r--r--src/mscorlib/src/System/Security/Policy/URL.cs29
-rw-r--r--src/mscorlib/src/System/Security/Policy/Zone.cs66
-rw-r--r--src/mscorlib/src/System/Security/Principal/TokenImpersonationLevel.cs9
-rw-r--r--src/mscorlib/src/System/Security/SafeSecurityHandles.cs16
-rw-r--r--src/mscorlib/src/System/Security/SecurityContext.cs238
-rw-r--r--src/mscorlib/src/System/Security/SecurityElement.cs100
-rw-r--r--src/mscorlib/src/System/Security/SecurityException.cs608
-rw-r--r--src/mscorlib/src/System/Security/SecurityManager.cs524
-rw-r--r--src/mscorlib/src/System/Security/SecurityRuntime.cs156
-rw-r--r--src/mscorlib/src/System/Security/SecurityState.cs10
-rw-r--r--src/mscorlib/src/System/Security/Util/Config.cs48
-rw-r--r--src/mscorlib/src/System/Security/Util/Hex.cs2
-rw-r--r--src/mscorlib/src/System/Security/Util/StringExpressionSet.cs41
-rw-r--r--src/mscorlib/src/System/Security/Util/TokenBasedSet.cs32
-rw-r--r--src/mscorlib/src/System/Security/Util/URLString.cs17
-rw-r--r--src/mscorlib/src/System/Security/Util/XMLUtil.cs272
-rw-r--r--src/mscorlib/src/System/Security/securestring.cs31
-rw-r--r--src/mscorlib/src/System/SharedStatics.cs64
-rw-r--r--src/mscorlib/src/System/Single.cs16
-rw-r--r--src/mscorlib/src/System/Span.cs477
-rw-r--r--src/mscorlib/src/System/String.Comparison.cs82
-rw-r--r--src/mscorlib/src/System/String.Manipulation.cs475
-rw-r--r--src/mscorlib/src/System/String.Searching.cs36
-rw-r--r--src/mscorlib/src/System/String.cs126
-rw-r--r--src/mscorlib/src/System/StringComparer.cs35
-rw-r--r--src/mscorlib/src/System/StubHelpers.cs161
-rw-r--r--src/mscorlib/src/System/Text/ASCIIEncoding.cs77
-rw-r--r--src/mscorlib/src/System/Text/BaseCodePageEncoding.cs30
-rw-r--r--src/mscorlib/src/System/Text/CodePageEncoding.cs13
-rw-r--r--src/mscorlib/src/System/Text/DBCSCodePageEncoding.cs102
-rw-r--r--src/mscorlib/src/System/Text/Decoder.cs32
-rw-r--r--src/mscorlib/src/System/Text/DecoderBestFitFallback.cs9
-rw-r--r--src/mscorlib/src/System/Text/DecoderFallback.cs13
-rw-r--r--src/mscorlib/src/System/Text/DecoderNLS.cs43
-rw-r--r--src/mscorlib/src/System/Text/DecoderReplacementFallback.cs9
-rw-r--r--src/mscorlib/src/System/Text/EUCJPEncoding.cs3
-rw-r--r--src/mscorlib/src/System/Text/Encoder.cs32
-rw-r--r--src/mscorlib/src/System/Text/EncoderBestFitFallback.cs12
-rw-r--r--src/mscorlib/src/System/Text/EncoderExceptionFallback.cs6
-rw-r--r--src/mscorlib/src/System/Text/EncoderFallback.cs8
-rw-r--r--src/mscorlib/src/System/Text/EncoderNLS.cs43
-rw-r--r--src/mscorlib/src/System/Text/EncoderReplacementFallback.cs10
-rw-r--r--src/mscorlib/src/System/Text/Encoding.cs222
-rw-r--r--src/mscorlib/src/System/Text/EncodingForwarder.cs98
-rw-r--r--src/mscorlib/src/System/Text/EncodingNLS.cs4
-rw-r--r--src/mscorlib/src/System/Text/EncodingProvider.cs2
-rw-r--r--src/mscorlib/src/System/Text/GB18030Encoding.cs60
-rw-r--r--src/mscorlib/src/System/Text/ISCIIEncoding.cs88
-rw-r--r--src/mscorlib/src/System/Text/ISO2022Encoding.cs74
-rw-r--r--src/mscorlib/src/System/Text/Latin1Encoding.cs66
-rw-r--r--src/mscorlib/src/System/Text/MLangCodePageEncoding.cs19
-rw-r--r--src/mscorlib/src/System/Text/Normalization.Unix.cs123
-rw-r--r--src/mscorlib/src/System/Text/Normalization.Windows.cs286
-rw-r--r--src/mscorlib/src/System/Text/Normalization.cs314
-rw-r--r--src/mscorlib/src/System/Text/SBCSCodePageEncoding.cs93
-rw-r--r--src/mscorlib/src/System/Text/StringBuilder.cs309
-rw-r--r--src/mscorlib/src/System/Text/SurrogateEncoder.cs7
-rw-r--r--src/mscorlib/src/System/Text/UTF32Encoding.cs71
-rw-r--r--src/mscorlib/src/System/Text/UTF7Encoding.cs55
-rw-r--r--src/mscorlib/src/System/Text/UTF8Encoding.cs96
-rw-r--r--src/mscorlib/src/System/Text/UnicodeEncoding.cs92
-rw-r--r--src/mscorlib/src/System/Threading/AsyncLocal.cs387
-rw-r--r--src/mscorlib/src/System/Threading/AutoResetEvent.cs1
-rw-r--r--src/mscorlib/src/System/Threading/CancellationToken.cs14
-rw-r--r--src/mscorlib/src/System/Threading/CancellationTokenRegistration.cs1
-rw-r--r--src/mscorlib/src/System/Threading/CancellationTokenSource.cs37
-rw-r--r--src/mscorlib/src/System/Threading/CountdownEvent.cs23
-rw-r--r--src/mscorlib/src/System/Threading/EventWaitHandle.cs69
-rw-r--r--src/mscorlib/src/System/Threading/ExecutionContext.cs1222
-rw-r--r--src/mscorlib/src/System/Threading/Interlocked.cs17
-rw-r--r--src/mscorlib/src/System/Threading/LazyInitializer.cs4
-rw-r--r--src/mscorlib/src/System/Threading/LockRecursionException.cs3
-rw-r--r--src/mscorlib/src/System/Threading/ManualResetEvent.cs1
-rw-r--r--src/mscorlib/src/System/Threading/ManualResetEventSlim.cs33
-rw-r--r--src/mscorlib/src/System/Threading/Monitor.cs26
-rw-r--r--src/mscorlib/src/System/Threading/Mutex.cs208
-rw-r--r--src/mscorlib/src/System/Threading/Overlapped.cs42
-rw-r--r--src/mscorlib/src/System/Threading/ReaderWriterLock.cs36
-rw-r--r--src/mscorlib/src/System/Threading/Semaphore.cs35
-rw-r--r--src/mscorlib/src/System/Threading/SemaphoreFullException.cs3
-rw-r--r--src/mscorlib/src/System/Threading/SemaphoreSlim.cs50
-rw-r--r--src/mscorlib/src/System/Threading/SpinLock.cs110
-rw-r--r--src/mscorlib/src/System/Threading/SpinWait.cs18
-rw-r--r--src/mscorlib/src/System/Threading/SynchronizationContext.cs90
-rw-r--r--src/mscorlib/src/System/Threading/Tasks/AsyncCausalityTracer.cs4
-rw-r--r--src/mscorlib/src/System/Threading/Tasks/BeginEndAwaitableAdapter.cs16
-rw-r--r--src/mscorlib/src/System/Threading/Tasks/ConcurrentExclusiveSchedulerPair.cs42
-rw-r--r--src/mscorlib/src/System/Threading/Tasks/FutureFactory.cs148
-rw-r--r--src/mscorlib/src/System/Threading/Tasks/Parallel.cs229
-rw-r--r--src/mscorlib/src/System/Threading/Tasks/ParallelLoopState.cs7
-rw-r--r--src/mscorlib/src/System/Threading/Tasks/ParallelRangeManager.cs9
-rw-r--r--src/mscorlib/src/System/Threading/Tasks/ProducerConsumerQueues.cs12
-rw-r--r--src/mscorlib/src/System/Threading/Tasks/TPLETWProvider.cs12
-rw-r--r--src/mscorlib/src/System/Threading/Tasks/Task.cs229
-rw-r--r--src/mscorlib/src/System/Threading/Tasks/TaskCompletionSource.cs6
-rw-r--r--src/mscorlib/src/System/Threading/Tasks/TaskContinuation.cs64
-rw-r--r--src/mscorlib/src/System/Threading/Tasks/TaskExceptionHolder.cs36
-rw-r--r--src/mscorlib/src/System/Threading/Tasks/TaskFactory.cs100
-rw-r--r--src/mscorlib/src/System/Threading/Tasks/TaskScheduler.cs21
-rw-r--r--src/mscorlib/src/System/Threading/Tasks/TaskToApm.cs5
-rw-r--r--src/mscorlib/src/System/Threading/Tasks/ThreadPoolTaskScheduler.cs7
-rw-r--r--src/mscorlib/src/System/Threading/Tasks/future.cs27
-rw-r--r--src/mscorlib/src/System/Threading/Thread.cs633
-rw-r--r--src/mscorlib/src/System/Threading/ThreadAbortException.cs1
-rw-r--r--src/mscorlib/src/System/Threading/ThreadLocal.cs17
-rw-r--r--src/mscorlib/src/System/Threading/ThreadPool.cs230
-rw-r--r--src/mscorlib/src/System/Threading/Timer.cs79
-rw-r--r--src/mscorlib/src/System/Threading/Volatile.cs6
-rw-r--r--src/mscorlib/src/System/Threading/WaitHandle.cs83
-rw-r--r--src/mscorlib/src/System/Threading/WaitHandleCannotBeOpenedException.cs4
-rw-r--r--src/mscorlib/src/System/Threading/WaitHandleExtensions.cs46
-rw-r--r--src/mscorlib/src/System/ThrowHelper.cs211
-rw-r--r--src/mscorlib/src/System/TimeSpan.cs28
-rw-r--r--src/mscorlib/src/System/TimeZone.cs4
-rw-r--r--src/mscorlib/src/System/TimeZoneInfo.cs641
-rw-r--r--src/mscorlib/src/System/TimeZoneNotFoundException.cs3
-rw-r--r--src/mscorlib/src/System/Tuple.cs23
-rw-r--r--src/mscorlib/src/System/Type.cs144
-rw-r--r--src/mscorlib/src/System/TypeInitializationException.cs1
-rw-r--r--src/mscorlib/src/System/TypeLoadException.cs9
-rw-r--r--src/mscorlib/src/System/TypeNameParser.cs30
-rw-r--r--src/mscorlib/src/System/TypedReference.cs10
-rw-r--r--src/mscorlib/src/System/UInt16.cs4
-rw-r--r--src/mscorlib/src/System/UInt32.cs4
-rw-r--r--src/mscorlib/src/System/UInt64.cs4
-rw-r--r--src/mscorlib/src/System/UIntPtr.cs25
-rw-r--r--src/mscorlib/src/System/UnSafeCharBuffer.cs57
-rw-r--r--src/mscorlib/src/System/UnhandledExceptionEventHandler.cs3
-rw-r--r--src/mscorlib/src/System/UnitySerializationHolder.cs4
-rw-r--r--src/mscorlib/src/System/ValueType.cs4
-rw-r--r--src/mscorlib/src/System/Variant.cs27
-rw-r--r--src/mscorlib/src/System/Version.cs164
-rw-r--r--src/mscorlib/src/System/WeakReference.cs23
-rw-r--r--src/mscorlib/src/System/WeakReferenceOfT.cs10
-rw-r--r--src/mscorlib/src/System/_LocalDataStore.cs6
-rw-r--r--src/mscorlib/src/System/_LocalDataStoreMgr.cs13
-rw-r--r--src/mscorlib/src/System/__ComObject.cs13
-rw-r--r--src/mscorlib/src/System/cominterfaces.cs34
-rw-r--r--src/mscorlib/src/System/mda.cs11
-rw-r--r--src/mscorlib/src/mscorlib.Friends.cs2
-rw-r--r--src/mscorlib/src/mscorlib.txt3494
777 files changed, 33737 insertions, 53299 deletions
diff --git a/src/mscorlib/Common/PinnableBufferCache.cs b/src/mscorlib/Common/PinnableBufferCache.cs
index fee3e46f46..fc6e13a899 100644
--- a/src/mscorlib/Common/PinnableBufferCache.cs
+++ b/src/mscorlib/Common/PinnableBufferCache.cs
@@ -4,9 +4,6 @@
#define ENABLE
#define MINBUFFERS
using System;
-#if !FEATURE_CORECLR
-using System.Diagnostics.Tracing;
-#endif
using System.Runtime.InteropServices;
using System.Runtime.ConstrainedExecution;
using System.Collections.Generic;
@@ -45,12 +42,6 @@ namespace System
/// Create a PinnableBufferCache that works on any object (it is intended for OverlappedData)
/// This is only used in mscorlib.
/// </summary>
-#if (ENABLE || MINBUFFERS)
-#pragma warning disable 618
- [EnvironmentPermission(SecurityAction.Assert, Unrestricted = true)]
-#pragma warning restore 618
- [System.Security.SecuritySafeCritical]
-#endif
internal PinnableBufferCache(string cacheName, Func<object> factory)
{
m_NotGen2 = new List<object>(DefaultNumberOfBuffers);
@@ -103,7 +94,6 @@ namespace System
/// <summary>
/// Get a object from the buffer manager. If no buffers exist, allocate a new one.
/// </summary>
- [System.Security.SecuritySafeCritical]
internal object Allocate()
{
#if ENABLE
@@ -149,7 +139,6 @@ namespace System
/// <summary>
/// Return a buffer back to the buffer manager.
/// </summary>
- [System.Security.SecuritySafeCritical]
internal void Free(object buffer)
{
#if ENABLE
@@ -188,7 +177,6 @@ namespace System
/// Called when we don't have any buffers in our free list to give out.
/// </summary>
/// <returns></returns>
- [System.Security.SecuritySafeCritical]
private void Restock(out object returnBuffer)
{
lock (this)
@@ -241,7 +229,6 @@ namespace System
/// <summary>
/// See if we can promote the buffers to the free list. Returns true if sucessful.
/// </summary>
- [System.Security.SecuritySafeCritical]
private bool AgePendingBuffers()
{
if (m_gen1CountAtLastRestock < GC.CollectionCount(GC.MaxGeneration - 1))
@@ -317,7 +304,6 @@ namespace System
/// otherwise, we root the cache to the Gen2GcCallback object, and leak the cache even when
/// the application no longer needs it.
/// </summary>
- [System.Security.SecuritySafeCritical]
private static bool Gen2GcCallbackFunc(object targetObj)
{
return ((PinnableBufferCache)(targetObj)).TrimFreeListIfNeeded();
@@ -328,7 +314,6 @@ namespace System
/// NOTE: DO NOT CALL THIS DIRECTLY FROM THE GEN2GCCALLBACK. INSTEAD CALL IT VIA A STATIC FUNCTION (SEE ABOVE).
/// If you register a non-static function as a callback, then this object will be leaked.
/// </summary>
- [System.Security.SecuritySafeCritical]
private bool TrimFreeListIfNeeded()
{
int curMSec = Environment.TickCount;
@@ -481,7 +466,6 @@ namespace System
/// </summary>
internal sealed class Gen2GcCallback : CriticalFinalizerObject
{
- [System.Security.SecuritySafeCritical]
public Gen2GcCallback()
: base()
{
@@ -506,14 +490,12 @@ namespace System
private Func<object, bool> m_callback;
private GCHandle m_weakTargetObj;
- [System.Security.SecuritySafeCritical]
private void Setup(Func<object, bool> callback, object targetObj)
{
m_callback = callback;
m_weakTargetObj = GCHandle.Alloc(targetObj, GCHandleType.Weak);
}
- [System.Security.SecuritySafeCritical]
~Gen2GcCallback()
{
// Check to see if the target object is still alive.
@@ -549,8 +531,6 @@ namespace System
#endregion
}
-
-#if FEATURE_CORECLR
internal sealed class PinnableBufferCacheEventSource
{
public static readonly PinnableBufferCacheEventSource Log = new PinnableBufferCacheEventSource();
@@ -581,86 +561,9 @@ namespace System
return 0;
}
- [System.Security.SecuritySafeCritical]
static internal unsafe long AddressOfObject(byte[] array)
{
return 0;
}
}
-#else
- /// <summary>
- /// PinnableBufferCacheEventSource is a private eventSource that we are using to
- /// debug and monitor the effectiveness of PinnableBufferCache
- /// </summary>
-#if PINNABLEBUFFERCACHE_MSCORLIB
- [EventSource(Name = "Microsoft-DotNETRuntime-PinnableBufferCache")]
-#else
- [EventSource(Name = "Microsoft-DotNETRuntime-PinnableBufferCache-System")]
-#endif
- internal sealed class PinnableBufferCacheEventSource : EventSource
- {
- public static readonly PinnableBufferCacheEventSource Log = new PinnableBufferCacheEventSource();
-
- [Event(1, Level = EventLevel.Verbose)]
- public void DebugMessage(string message) { if (IsEnabled()) WriteEvent(1, message); }
- [Event(2, Level = EventLevel.Verbose)]
- public void DebugMessage1(string message, long value) { if (IsEnabled()) WriteEvent(2, message, value); }
- [Event(3, Level = EventLevel.Verbose)]
- public void DebugMessage2(string message, long value1, long value2) { if (IsEnabled()) WriteEvent(3, message, value1, value2); }
- [Event(18, Level = EventLevel.Verbose)]
- public void DebugMessage3(string message, long value1, long value2, long value3) { if (IsEnabled()) WriteEvent(18, message, value1, value2, value3); }
-
- [Event(4)]
- public void Create(string cacheName) { if (IsEnabled()) WriteEvent(4, cacheName); }
-
- [Event(5, Level = EventLevel.Verbose)]
- public void AllocateBuffer(string cacheName, ulong objectId, int objectHash, int objectGen, int freeCountAfter) { if (IsEnabled()) WriteEvent(5, cacheName, objectId, objectHash, objectGen, freeCountAfter); }
- [Event(6)]
- public void AllocateBufferFromNotGen2(string cacheName, int notGen2CountAfter) { if (IsEnabled()) WriteEvent(6, cacheName, notGen2CountAfter); }
- [Event(7)]
- public void AllocateBufferCreatingNewBuffers(string cacheName, int totalBuffsBefore, int objectCount) { if (IsEnabled()) WriteEvent(7, cacheName, totalBuffsBefore, objectCount); }
- [Event(8)]
- public void AllocateBufferAged(string cacheName, int agedCount) { if (IsEnabled()) WriteEvent(8, cacheName, agedCount); }
- [Event(9)]
- public void AllocateBufferFreeListEmpty(string cacheName, int notGen2CountBefore) { if (IsEnabled()) WriteEvent(9, cacheName, notGen2CountBefore); }
-
- [Event(10, Level = EventLevel.Verbose)]
- public void FreeBuffer(string cacheName, ulong objectId, int objectHash, int freeCountBefore) { if (IsEnabled()) WriteEvent(10, cacheName, objectId, objectHash, freeCountBefore); }
- [Event(11)]
- public void FreeBufferStillTooYoung(string cacheName, int notGen2CountBefore) { if (IsEnabled()) WriteEvent(11, cacheName, notGen2CountBefore); }
-
- [Event(13)]
- public void TrimCheck(string cacheName, int totalBuffs, bool neededMoreThanFreeList, int deltaMSec) { if (IsEnabled()) WriteEvent(13, cacheName, totalBuffs, neededMoreThanFreeList, deltaMSec); }
- [Event(14)]
- public void TrimFree(string cacheName, int totalBuffs, int freeListCount, int toBeFreed) { if (IsEnabled()) WriteEvent(14, cacheName, totalBuffs, freeListCount, toBeFreed); }
- [Event(15)]
- public void TrimExperiment(string cacheName, int totalBuffs, int freeListCount, int numTrimTrial) { if (IsEnabled()) WriteEvent(15, cacheName, totalBuffs, freeListCount, numTrimTrial); }
- [Event(16)]
- public void TrimFreeSizeOK(string cacheName, int totalBuffs, int freeListCount) { if (IsEnabled()) WriteEvent(16, cacheName, totalBuffs, freeListCount); }
- [Event(17)]
- public void TrimFlush(string cacheName, int totalBuffs, int freeListCount, int notGen2CountBefore) { if (IsEnabled()) WriteEvent(17, cacheName, totalBuffs, freeListCount, notGen2CountBefore); }
- [Event(20)]
- public void AgePendingBuffersResults(string cacheName, int promotedToFreeListCount, int heldBackCount) { if (IsEnabled()) WriteEvent(20, cacheName, promotedToFreeListCount, heldBackCount); }
- [Event(21)]
- public void WalkFreeListResult(string cacheName, int freeListCount, int gen0BuffersInFreeList) { if (IsEnabled()) WriteEvent(21, cacheName, freeListCount, gen0BuffersInFreeList); }
-
-
- static internal ulong AddressOf(object obj)
- {
- var asByteArray = obj as byte[];
- if (asByteArray != null)
- return (ulong)AddressOfByteArray(asByteArray);
- return 0;
- }
-
- [System.Security.SecuritySafeCritical]
- static internal unsafe long AddressOfByteArray(byte[] array)
- {
- if (array == null)
- return 0;
- fixed (byte* ptr = array)
- return (long)(ptr - 2 * sizeof(void*));
- }
- }
-#endif
}
diff --git a/src/mscorlib/System.Private.CoreLib.csproj b/src/mscorlib/System.Private.CoreLib.csproj
index c14ce422fb..f1f944a6f6 100644
--- a/src/mscorlib/System.Private.CoreLib.csproj
+++ b/src/mscorlib/System.Private.CoreLib.csproj
@@ -1,5 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+
+ <!-- Always use latest Roslyn compiler -->
+ <Import Project="..\..\Tools\net45\roslyn\build\Microsoft.Net.Compilers.props" Condition="'$(OS)'=='Windows_NT' and '$(UseLegacyCompiler)'!='true'" />
+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<!-- Include common build properties -->
diff --git a/src/mscorlib/System.Private.CoreLib.sln b/src/mscorlib/System.Private.CoreLib.sln
index 4ab28af2d9..60a2316957 100644
--- a/src/mscorlib/System.Private.CoreLib.sln
+++ b/src/mscorlib/System.Private.CoreLib.sln
@@ -5,6 +5,11 @@ VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Private.CoreLib", "System.Private.CoreLib.csproj", "{3DA06C3A-2E7B-4CB7-80ED-9B12916013F9}"
EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{E16B1C86-C275-495B-80D6-7CE8196A18B4}"
+ ProjectSection(SolutionItems) = preProject
+ model.xml = model.xml
+ EndProjectSection
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Checked|amd64 = Checked|amd64
diff --git a/src/mscorlib/corefx/Debug.cs b/src/mscorlib/corefx/Debug.cs
new file mode 100644
index 0000000000..3398c0e31e
--- /dev/null
+++ b/src/mscorlib/corefx/Debug.cs
@@ -0,0 +1,29 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .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 class Debug
+ {
+ [Conditional("_DEBUG")]
+ static public void Assert(bool condition)
+ {
+ BCLDebug.Assert(condition);
+ }
+
+ [Conditional("_DEBUG")]
+ static public void Assert(bool condition, string message)
+ {
+ BCLDebug.Assert(condition, message);
+ }
+
+ [Conditional("_DEBUG")]
+ static public void Fail(string message)
+ {
+ BCLDebug.Assert(false, message);
+ }
+ }
+} \ No newline at end of file
diff --git a/src/mscorlib/corefx/Interop/Unix/Interop.Errors.cs b/src/mscorlib/corefx/Interop/Unix/Interop.Errors.cs
new file mode 100644
index 0000000000..4248434db3
--- /dev/null
+++ b/src/mscorlib/corefx/Interop/Unix/Interop.Errors.cs
@@ -0,0 +1,207 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .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.
+ 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.
+ 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.
+
+ // 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 string.Format(
+ "RawErrno: {0} Error: {1} GetErrorMessage: {2}", // No localization required; text is member names used for debugging purposes
+ RawErrno, Error, GetErrorMessage());
+ }
+ }
+
+ internal 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 unsafe extern 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/src/mscorlib/corefx/Interop/Unix/Interop.IOErrors.cs b/src/mscorlib/corefx/Interop/Unix/Interop.IOErrors.cs
new file mode 100644
index 0000000000..e9d6ce61d6
--- /dev/null
+++ b/src/mscorlib/corefx/Interop/Unix/Interop.IOErrors.cs
@@ -0,0 +1,170 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .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;
+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="error">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 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/src/mscorlib/corefx/Interop/Unix/Interop.Libraries.cs b/src/mscorlib/corefx/Interop/Unix/Interop.Libraries.cs
index f8c5b26e44..a11a23ce8c 100644
--- a/src/mscorlib/corefx/Interop/Unix/Interop.Libraries.cs
+++ b/src/mscorlib/corefx/Interop/Unix/Interop.Libraries.cs
@@ -7,5 +7,12 @@ internal static partial class Interop
private static partial class Libraries
{
internal const string GlobalizationInterop = "System.Globalization.Native"; // CoreFX wrappers for ICU
+ // Shims
+ internal const string SystemNative = "System.Native";
+ internal const string HttpNative = "System.Net.Http.Native";
+ internal const string NetSecurityNative = "System.Net.Security.Native";
+ internal const string CryptoNative = "System.Security.Cryptography.Native.OpenSsl";
+ internal const string GlobalizationNative = "System.Globalization.Native";
+ internal const string CompressionNative = "System.IO.Compression.Native";
}
}
diff --git a/src/mscorlib/corefx/Interop/Unix/System.Globalization.Native/Interop.Collation.cs b/src/mscorlib/corefx/Interop/Unix/System.Globalization.Native/Interop.Collation.cs
index 6acf55e17b..eb9e0743bc 100644
--- a/src/mscorlib/corefx/Interop/Unix/System.Globalization.Native/Interop.Collation.cs
+++ b/src/mscorlib/corefx/Interop/Unix/System.Globalization.Native/Interop.Collation.cs
@@ -13,7 +13,7 @@ internal static partial class Interop
{
[SecurityCritical]
[DllImport(Libraries.GlobalizationInterop, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_GetSortHandle")]
- internal unsafe static extern SafeSortHandle GetSortHandle(byte[] localeName);
+ internal unsafe static extern ResultCode GetSortHandle(byte[] localeName, out SafeSortHandle sortHandle);
[SecurityCritical]
[DllImport(Libraries.GlobalizationInterop, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_CloseSortHandle")]
@@ -53,6 +53,9 @@ internal static partial class Interop
[DllImport(Libraries.GlobalizationInterop, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_CompareStringOrdinalIgnoreCase")]
internal unsafe static extern int CompareStringOrdinalIgnoreCase(char* lpStr1, int cwStr1Len, char* lpStr2, int cwStr2Len);
+ [DllImport(Libraries.GlobalizationInterop, EntryPoint = "GlobalizationNative_GetSortVersion")]
+ internal static extern int GetSortVersion();
+
[SecurityCritical]
internal class SafeSortHandle : SafeHandle
{
diff --git a/src/mscorlib/corefx/Interop/Unix/System.Globalization.Native/Interop.Idna.cs b/src/mscorlib/corefx/Interop/Unix/System.Globalization.Native/Interop.Idna.cs
new file mode 100644
index 0000000000..43c72281ae
--- /dev/null
+++ b/src/mscorlib/corefx/Interop/Unix/System.Globalization.Native/Interop.Idna.cs
@@ -0,0 +1,21 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .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 GlobalizationInterop
+ {
+ internal const int AllowUnassigned = 0x1;
+ internal const int UseStd3AsciiRules = 0x2;
+
+ [DllImport(Libraries.GlobalizationInterop, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_ToAscii")]
+ internal static unsafe extern int ToAscii(uint flags, char* src, int srcLen, char* dstBuffer, int dstBufferCapacity);
+
+ [DllImport(Libraries.GlobalizationInterop, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_ToUnicode")]
+ internal static unsafe extern int ToUnicode(uint flags, char* src, int srcLen, char* dstBuffer, int dstBufferCapacity);
+ }
+}
diff --git a/src/mscorlib/corefx/Interop/Unix/System.Globalization.Native/Interop.Locale.cs b/src/mscorlib/corefx/Interop/Unix/System.Globalization.Native/Interop.Locale.cs
index 3912581c73..fcea708ee8 100644
--- a/src/mscorlib/corefx/Interop/Unix/System.Globalization.Native/Interop.Locale.cs
+++ b/src/mscorlib/corefx/Interop/Unix/System.Globalization.Native/Interop.Locale.cs
@@ -33,5 +33,8 @@ internal static partial class Interop
[DllImport(Libraries.GlobalizationInterop, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_GetLocaleInfoGroupingSizes")]
[return: MarshalAs(UnmanagedType.Bool)]
internal unsafe static extern bool GetLocaleInfoGroupingSizes(string localeName, uint localeGroupingData, ref int primaryGroupSize, ref int secondaryGroupSize);
+
+ [DllImport(Libraries.GlobalizationInterop, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_GetLocales")]
+ internal unsafe static extern int GetLocales([Out] Char[] value, int valueLength);
}
}
diff --git a/src/mscorlib/corefx/Interop/Unix/System.Globalization.Native/Interop.Normalization.cs b/src/mscorlib/corefx/Interop/Unix/System.Globalization.Native/Interop.Normalization.cs
new file mode 100644
index 0000000000..c4cb9fb851
--- /dev/null
+++ b/src/mscorlib/corefx/Interop/Unix/System.Globalization.Native/Interop.Normalization.cs
@@ -0,0 +1,19 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .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 GlobalizationInterop
+ {
+ [DllImport(Libraries.GlobalizationInterop, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_IsNormalized")]
+ internal static extern int IsNormalized(NormalizationForm normalizationForm, string src, int srcLen);
+
+ [DllImport(Libraries.GlobalizationInterop, 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/src/mscorlib/corefx/Interop/Unix/System.Globalization.Native/Interop.ResultCode.cs b/src/mscorlib/corefx/Interop/Unix/System.Globalization.Native/Interop.ResultCode.cs
index 4621580063..cca6ae4dcb 100644
--- a/src/mscorlib/corefx/Interop/Unix/System.Globalization.Native/Interop.ResultCode.cs
+++ b/src/mscorlib/corefx/Interop/Unix/System.Globalization.Native/Interop.ResultCode.cs
@@ -12,6 +12,7 @@ internal static partial class Interop
Success = 0,
UnknownError = 1,
InsufficentBuffer = 2,
+ OutOfMemory = 3
}
}
}
diff --git a/src/mscorlib/corefx/Interop/Unix/System.Native/Interop.Close.cs b/src/mscorlib/corefx/Interop/Unix/System.Native/Interop.Close.cs
new file mode 100644
index 0000000000..8d192398a0
--- /dev/null
+++ b/src/mscorlib/corefx/Interop/Unix/System.Native/Interop.Close.cs
@@ -0,0 +1,15 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using 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/src/mscorlib/corefx/Interop/Unix/System.Native/Interop.FLock.cs b/src/mscorlib/corefx/Interop/Unix/System.Native/Interop.FLock.cs
new file mode 100644
index 0000000000..22934a3e77
--- /dev/null
+++ b/src/mscorlib/corefx/Interop/Unix/System.Native/Interop.FLock.cs
@@ -0,0 +1,31 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .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/src/mscorlib/corefx/Interop/Unix/System.Native/Interop.FSync.cs b/src/mscorlib/corefx/Interop/Unix/System.Native/Interop.FSync.cs
new file mode 100644
index 0000000000..e3ab970931
--- /dev/null
+++ b/src/mscorlib/corefx/Interop/Unix/System.Native/Interop.FSync.cs
@@ -0,0 +1,15 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using 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/src/mscorlib/corefx/Interop/Unix/System.Native/Interop.FTruncate.cs b/src/mscorlib/corefx/Interop/Unix/System.Native/Interop.FTruncate.cs
new file mode 100644
index 0000000000..5dad650362
--- /dev/null
+++ b/src/mscorlib/corefx/Interop/Unix/System.Native/Interop.FTruncate.cs
@@ -0,0 +1,15 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using 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/src/mscorlib/corefx/Interop/Unix/System.Native/Interop.Fcntl.cs b/src/mscorlib/corefx/Interop/Unix/System.Native/Interop.Fcntl.cs
new file mode 100644
index 0000000000..23b48a4f5d
--- /dev/null
+++ b/src/mscorlib/corefx/Interop/Unix/System.Native/Interop.Fcntl.cs
@@ -0,0 +1,21 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .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/src/mscorlib/corefx/Interop/Unix/System.Native/Interop.GetCwd.cs b/src/mscorlib/corefx/Interop/Unix/System.Native/Interop.GetCwd.cs
new file mode 100644
index 0000000000..724e342342
--- /dev/null
+++ b/src/mscorlib/corefx/Interop/Unix/System.Native/Interop.GetCwd.cs
@@ -0,0 +1,74 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .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_GetCwd", SetLastError = true)]
+ private static unsafe extern 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
+ // until we get one that works or until we hit MaxPath.
+ int maxPath = Interop.Sys.MaxPath;
+ if (StackLimit < maxPath)
+ {
+ int bufferSize = StackLimit;
+ do
+ {
+ checked { bufferSize *= 2; }
+ var buf = new byte[Math.Min(bufferSize, maxPath)];
+ fixed (byte* ptr = buf)
+ {
+ result = GetCwdHelper(ptr, buf.Length);
+ if (result != null)
+ {
+ return result;
+ }
+ }
+ }
+ while (bufferSize < maxPath);
+ }
+
+ // If we couldn't get the cwd with a MaxPath-sized buffer, something's wrong.
+ throw Interop.GetExceptionForIoErrno(new ErrorInfo(Interop.Error.ENAMETOOLONG));
+ }
+
+ 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/src/mscorlib/corefx/Interop/Unix/System.Native/Interop.GetUnixName.cs b/src/mscorlib/corefx/Interop/Unix/System.Native/Interop.GetUnixName.cs
new file mode 100644
index 0000000000..33664c4d39
--- /dev/null
+++ b/src/mscorlib/corefx/Interop/Unix/System.Native/Interop.GetUnixName.cs
@@ -0,0 +1,21 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .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/src/mscorlib/corefx/Interop/Unix/System.Native/Interop.LSeek.cs b/src/mscorlib/corefx/Interop/Unix/System.Native/Interop.LSeek.cs
new file mode 100644
index 0000000000..7f8df7c6bf
--- /dev/null
+++ b/src/mscorlib/corefx/Interop/Unix/System.Native/Interop.LSeek.cs
@@ -0,0 +1,22 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .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/src/mscorlib/corefx/Interop/Unix/System.Native/Interop.MksTemps.cs b/src/mscorlib/corefx/Interop/Unix/System.Native/Interop.MksTemps.cs
new file mode 100644
index 0000000000..b8694d9007
--- /dev/null
+++ b/src/mscorlib/corefx/Interop/Unix/System.Native/Interop.MksTemps.cs
@@ -0,0 +1,17 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .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/src/mscorlib/corefx/Interop/Unix/System.Native/Interop.Open.cs b/src/mscorlib/corefx/Interop/Unix/System.Native/Interop.Open.cs
new file mode 100644
index 0000000000..a9a994c78c
--- /dev/null
+++ b/src/mscorlib/corefx/Interop/Unix/System.Native/Interop.Open.cs
@@ -0,0 +1,15 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using 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/src/mscorlib/corefx/Interop/Unix/System.Native/Interop.OpenFlags.cs b/src/mscorlib/corefx/Interop/Unix/System.Native/Interop.OpenFlags.cs
new file mode 100644
index 0000000000..f9e54c3cbc
--- /dev/null
+++ b/src/mscorlib/corefx/Interop/Unix/System.Native/Interop.OpenFlags.cs
@@ -0,0 +1,27 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+
+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/src/mscorlib/corefx/Interop/Unix/System.Native/Interop.PathConf.cs b/src/mscorlib/corefx/Interop/Unix/System.Native/Interop.PathConf.cs
new file mode 100644
index 0000000000..4a1fcf67d0
--- /dev/null
+++ b/src/mscorlib/corefx/Interop/Unix/System.Native/Interop.PathConf.cs
@@ -0,0 +1,73 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .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 static int DEFAULT_PC_NAME_MAX = 255;
+
+ 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,
+ }
+
+ /// <summary>The maximum path length for the system. -1 if it hasn't yet been initialized.</summary>
+ private static int s_maxPath = -1;
+
+ /// <summary>The maximum name length for the system. -1 if it hasn't yet been initialized.</summary>
+ private static int s_maxName = -1;
+
+ internal static int MaxPath
+ {
+ get
+ {
+ // Benign race condition on cached value
+ if (s_maxPath < 0)
+ {
+ // GetMaximumPath returns a long from PathConf
+ // but our callers expect an int so we need to convert.
+ long temp = GetMaximumPath();
+ if (temp > int.MaxValue)
+ s_maxPath = int.MaxValue;
+ else
+ s_maxPath = Convert.ToInt32(temp);
+ }
+ return s_maxPath;
+ }
+ }
+
+ internal static int MaxName
+ {
+ get
+ {
+ // Benign race condition on cached value
+ if (s_maxName < 0)
+ {
+ int result = PathConf("/", PathConfName.PC_NAME_MAX);
+ s_maxName = result >= 0 ? result : DEFAULT_PC_NAME_MAX;
+ }
+
+ return s_maxName;
+ }
+ }
+
+ [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_PathConf", SetLastError = true)]
+ private static extern int PathConf(string path, PathConfName name);
+
+ [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetMaximumPath")]
+ private static extern long GetMaximumPath();
+ }
+}
diff --git a/src/mscorlib/corefx/Interop/Unix/System.Native/Interop.Permissions.cs b/src/mscorlib/corefx/Interop/Unix/System.Native/Interop.Permissions.cs
new file mode 100644
index 0000000000..f1d13787d2
--- /dev/null
+++ b/src/mscorlib/corefx/Interop/Unix/System.Native/Interop.Permissions.cs
@@ -0,0 +1,32 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .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/src/mscorlib/corefx/Interop/Unix/System.Native/Interop.PosixFAdvise.cs b/src/mscorlib/corefx/Interop/Unix/System.Native/Interop.PosixFAdvise.cs
new file mode 100644
index 0000000000..69e39b30d2
--- /dev/null
+++ b/src/mscorlib/corefx/Interop/Unix/System.Native/Interop.PosixFAdvise.cs
@@ -0,0 +1,36 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .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 acessed 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/src/mscorlib/corefx/Interop/Unix/System.Native/Interop.Read.cs b/src/mscorlib/corefx/Interop/Unix/System.Native/Interop.Read.cs
new file mode 100644
index 0000000000..812ae348dc
--- /dev/null
+++ b/src/mscorlib/corefx/Interop/Unix/System.Native/Interop.Read.cs
@@ -0,0 +1,25 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .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 unsafe extern int Read(SafeFileHandle fd, byte* buffer, int count);
+ }
+}
diff --git a/src/mscorlib/corefx/Interop/Unix/System.Native/Interop.Stat.cs b/src/mscorlib/corefx/Interop/Unix/System.Native/Interop.Stat.cs
new file mode 100644
index 0000000000..a8bc2ec7d1
--- /dev/null
+++ b/src/mscorlib/corefx/Interop/Unix/System.Native/Interop.Stat.cs
@@ -0,0 +1,59 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .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 MTime;
+ internal long CTime;
+ internal long BirthTime;
+ }
+
+ 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/src/mscorlib/corefx/Interop/Unix/System.Native/Interop.Unlink.cs b/src/mscorlib/corefx/Interop/Unix/System.Native/Interop.Unlink.cs
new file mode 100644
index 0000000000..829210fa7e
--- /dev/null
+++ b/src/mscorlib/corefx/Interop/Unix/System.Native/Interop.Unlink.cs
@@ -0,0 +1,15 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using 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/src/mscorlib/corefx/Interop/Unix/System.Native/Interop.Write.cs b/src/mscorlib/corefx/Interop/Unix/System.Native/Interop.Write.cs
new file mode 100644
index 0000000000..c14fc26263
--- /dev/null
+++ b/src/mscorlib/corefx/Interop/Unix/System.Native/Interop.Write.cs
@@ -0,0 +1,27 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System.Runtime.InteropServices;
+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 unsafe extern int Write(SafeFileHandle fd, byte* buffer, int bufferSize);
+
+ [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_Write", SetLastError = true)]
+ internal static unsafe extern int Write(int fd, byte* buffer, int bufferSize);
+ }
+}
diff --git a/src/mscorlib/corefx/Interop/Windows/BCrypt/Interop.BCryptGenRandom.cs b/src/mscorlib/corefx/Interop/Windows/BCrypt/Interop.BCryptGenRandom.cs
new file mode 100644
index 0000000000..d2ce4131b0
--- /dev/null
+++ b/src/mscorlib/corefx/Interop/Windows/BCrypt/Interop.BCryptGenRandom.cs
@@ -0,0 +1,26 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .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 partial class Interop
+{
+ internal partial class BCrypt
+ {
+ internal static unsafe NTSTATUS BCryptGenRandom(byte* pbBuffer, int count)
+ {
+ Debug.Assert(pbBuffer != null);
+ Debug.Assert(count >= 0);
+
+ return BCryptGenRandom(IntPtr.Zero, pbBuffer, count, BCRYPT_USE_SYSTEM_PREFERRED_RNG);
+ }
+
+ private const int BCRYPT_USE_SYSTEM_PREFERRED_RNG = 0x00000002;
+
+ [DllImport(Libraries.BCrypt, CharSet = CharSet.Unicode)]
+ private static unsafe extern NTSTATUS BCryptGenRandom(IntPtr hAlgorithm, byte* pbBuffer, int cbBuffer, int dwFlags);
+ }
+}
diff --git a/src/mscorlib/corefx/Interop/Windows/BCrypt/Interop.NTSTATUS.cs b/src/mscorlib/corefx/Interop/Windows/BCrypt/Interop.NTSTATUS.cs
new file mode 100644
index 0000000000..49d674f399
--- /dev/null
+++ b/src/mscorlib/corefx/Interop/Windows/BCrypt/Interop.NTSTATUS.cs
@@ -0,0 +1,19 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .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 partial class Interop
+{
+ internal partial class BCrypt
+ {
+ internal enum NTSTATUS : uint
+ {
+ STATUS_SUCCESS = 0x0,
+ STATUS_NOT_FOUND = 0xc0000225,
+ STATUS_INVALID_PARAMETER = 0xc000000d,
+ STATUS_NO_MEMORY = 0xc0000017,
+ }
+ }
+}
diff --git a/src/mscorlib/corefx/Interop/Windows/Crypt32/Interop.CryptProtectMemory.cs b/src/mscorlib/corefx/Interop/Windows/Crypt32/Interop.CryptProtectMemory.cs
new file mode 100644
index 0000000000..b10cb6a041
--- /dev/null
+++ b/src/mscorlib/corefx/Interop/Windows/Crypt32/Interop.CryptProtectMemory.cs
@@ -0,0 +1,22 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .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 partial class Interop
+{
+ internal 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(SafeBSTRHandle pData, uint cbData, uint dwFlags);
+
+ [DllImport(Libraries.Crypt32, CharSet = CharSet.Unicode, SetLastError = true)]
+ internal static extern bool CryptUnprotectMemory(SafeBSTRHandle pData, uint cbData, uint dwFlags);
+ }
+}
diff --git a/src/mscorlib/corefx/Interop/Windows/Interop.BOOL.cs b/src/mscorlib/corefx/Interop/Windows/Interop.BOOL.cs
new file mode 100644
index 0000000000..9f4dab8935
--- /dev/null
+++ b/src/mscorlib/corefx/Interop/Windows/Interop.BOOL.cs
@@ -0,0 +1,21 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+internal partial class Interop
+{
+ /// <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/src/mscorlib/corefx/Interop/Windows/Interop.Libraries.cs b/src/mscorlib/corefx/Interop/Windows/Interop.Libraries.cs
new file mode 100644
index 0000000000..1165a2da95
--- /dev/null
+++ b/src/mscorlib/corefx/Interop/Windows/Interop.Libraries.cs
@@ -0,0 +1,82 @@
+// Licensed to the .NET Foundation under one or more 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 class Libraries
+ {
+ internal const string Advapi32 = "advapi32.dll";
+ internal const string BCrypt = "BCrypt.dll";
+ internal const string Combase = "combase.dll";
+ internal const string Console_L1 = "api-ms-win-core-console-l1-1-0.dll";
+ internal const string Console_L2 = "api-ms-win-core-console-l2-1-0.dll";
+ internal const string CoreFile_L1 = "api-ms-win-core-file-l1-1-0.dll";
+ internal const string CoreFile_L1_2 = "api-ms-win-core-file-l1-2-0.dll";
+ internal const string CoreFile_L2 = "api-ms-win-core-file-l2-1-0.dll";
+ internal const string Crypt32 = "crypt32.dll";
+ internal const string Debug = "api-ms-win-core-debug-l1-1-0.dll";
+ internal const string Error_L1 = "api-ms-win-core-winrt-error-l1-1-0.dll";
+ internal const string ErrorHandling = "api-ms-win-core-errorhandling-l1-1-0.dll";
+ internal const string Eventing = "api-ms-win-eventing-provider-l1-1-0.dll";
+ internal const string Handle = "api-ms-win-core-handle-l1-1-0.dll";
+ internal const string Heap = "api-ms-win-core-heap-obsolete-l1-1-0.dll";
+ internal const string Heap_L1 = "api-ms-win-core-heap-l1-1-0.dll";
+ internal const string IO = "api-ms-win-core-io-l1-1-0.dll";
+ internal const string IpHlpApi = "iphlpapi.dll";
+ internal const string Kernel32 = "kernel32.dll";
+ internal const string Kernel32_L1 = "api-ms-win-core-kernel32-legacy-l1-1-1.dll";
+ internal const string Kernel32_L2 = "api-ms-win-core-kernel32-legacy-l1-1-0.dll";
+ internal const string Keyboard = "ext-ms-win-ntuser-keyboard-l1-2-1.dll";
+ internal const string LibraryLoader = "api-ms-win-core-libraryloader-l1-1-0.dll";
+ internal const string Localization = "api-ms-win-core-localization-l1-2-0.dll";
+ internal const string Memory_L1_0 = "api-ms-win-core-memory-l1-1-0.dll";
+ internal const string Memory_L1_1 = "api-ms-win-core-memory-l1-1-1.dll";
+ internal const string Memory_L1_2 = "api-ms-win-core-memory-l1-1-2.dll";
+ internal const string Memory_L1_3 = "api-ms-win-core-memory-l1-1-3.dll";
+ internal const string NCrypt = "ncrypt.dll";
+ internal const string NtDll = "ntdll.dll";
+ internal const string OleAut32 = "oleaut32.dll";
+ internal const string Pipe = "api-ms-win-core-namedpipe-l1-1-0.dll";
+ internal const string Pipe_L2 = "api-ms-win-core-namedpipe-l1-2-1.dll";
+ internal const string ProcessEnvironment = "api-ms-win-core-processenvironment-l1-1-0.dll";
+ internal const string ProcessThread_L1 = "api-ms-win-core-processthreads-l1-1-0.dll";
+ internal const string ProcessThread_L1_1 = "api-ms-win-core-processthreads-l1-1-1.dll";
+ internal const string ProcessThread_L1_2 = "api-ms-win-core-processthreads-l1-1-2.dll";
+ internal const string ProcessTopology = "api-ms-win-core-processtopology-obsolete-l1-1-0.dll";
+ internal const string Profile = "api-ms-win-core-profile-l1-1-0.dll";
+ internal const string Psapi = "api-ms-win-core-psapi-l1-1-0.dll";
+ internal const string Psapi_Obsolete = "api-ms-win-core-psapi-obsolete-l1-1-0.dll";
+ internal const string Registry_L1 = "api-ms-win-core-registry-l1-1-0.dll";
+ internal const string Registry_L2 = "api-ms-win-core-registry-l2-1-0.dll";
+ internal const string RoBuffer = "api-ms-win-core-winrt-robuffer-l1-1-0.dll";
+ internal const string SecurityBase = "api-ms-win-security-base-l1-1-0.dll";
+ internal const string SecurityCpwl = "api-ms-win-security-cpwl-l1-1-0.dll";
+ internal const string SecurityCryptoApi = "api-ms-win-security-cryptoapi-l1-1-0.dll";
+ internal const string SecurityLsa = "api-ms-win-security-lsalookup-l2-1-0.dll";
+ internal const string SecurityLsaPolicy = "api-ms-win-security-lsapolicy-l1-1-0.dll";
+ internal const string SecurityProvider = "api-ms-win-security-provider-l1-1-0.dll";
+ internal const string SecuritySddl = "api-ms-win-security-sddl-l1-1-0.dll";
+ internal const string ServiceCore = "api-ms-win-service-core-l1-1-1.dll";
+ internal const string ServiceMgmt_L1 = "api-ms-win-service-management-l1-1-0.dll";
+ internal const string ServiceMgmt_L2 = "api-ms-win-service-management-l2-1-0.dll";
+ internal const string ServiceWinSvc = "api-ms-win-service-winsvc-l1-1-0.dll";
+ internal const string Shell = "shell32.dll";
+ internal const string ShellFolders = "ext-ms-win-shell32-shellfolders-l1-1-0.dll";
+ internal const string Sspi = "sspicli.dll";
+ internal const string String_L1 = "api-ms-win-core-string-l1-1-0.dll";
+ internal const string Synch = "api-ms-win-core-synch-l1-1-0.dll";
+ internal const string SystemInfo_L1_1 = "api-ms-win-core-sysinfo-l1-1-0.dll";
+ internal const string SystemInfo_L1_2 = "api-ms-win-core-sysinfo-l1-2-0.dll";
+ internal const string SystemInfo_L2_1 = "api-ms-win-core-sysinfo-l2-1-0.dll";
+ internal const string ThreadPool = "api-ms-win-core-threadpool-l1-2-0.dll";
+ internal const string User32 = "user32.dll";
+ internal const string Util = "api-ms-win-core-util-l1-1-0.dll";
+ internal const string Version = "api-ms-win-core-version-l1-1-0.dll";
+ internal const string WinHttp = "winhttp.dll";
+ internal const string Winsock = "Ws2_32.dll";
+ internal const string Wow64 = "api-ms-win-core-wow64-l1-1-0.dll";
+ internal const string Ws2_32 = "ws2_32.dll";
+ internal const string Zlib = "clrcompression.dll";
+ }
+}
diff --git a/src/mscorlib/corefx/Interop/Windows/NtDll/Interop.ZeroMemory.cs b/src/mscorlib/corefx/Interop/Windows/NtDll/Interop.ZeroMemory.cs
new file mode 100644
index 0000000000..caa0329bd0
--- /dev/null
+++ b/src/mscorlib/corefx/Interop/Windows/NtDll/Interop.ZeroMemory.cs
@@ -0,0 +1,19 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .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 partial class Interop
+{
+ internal partial class NtDll
+ {
+ [DllImport(Libraries.NtDll, CharSet = CharSet.Unicode, EntryPoint = "RtlZeroMemory")]
+ internal static extern void ZeroMemory(SafeBSTRHandle address, uint length);
+
+ [DllImport(Libraries.NtDll, CharSet = CharSet.Unicode, EntryPoint = "RtlZeroMemory")]
+ internal static extern void ZeroMemory(IntPtr address, UIntPtr length);
+ }
+}
diff --git a/src/mscorlib/corefx/Interop/Windows/mincore/Interop.CancelIoEx.cs b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.CancelIoEx.cs
new file mode 100644
index 0000000000..868d409321
--- /dev/null
+++ b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.CancelIoEx.cs
@@ -0,0 +1,16 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// 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;
+using System.Threading;
+
+internal partial class Interop
+{
+ internal partial class mincore
+ {
+ [DllImport(Libraries.IO, SetLastError = true)]
+ internal static unsafe extern bool CancelIoEx(SafeHandle handle, NativeOverlapped* lpOverlapped);
+ }
+}
diff --git a/src/mscorlib/corefx/Interop/Windows/mincore/Interop.CloseHandle.cs b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.CloseHandle.cs
new file mode 100644
index 0000000000..029937b6d5
--- /dev/null
+++ b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.CloseHandle.cs
@@ -0,0 +1,16 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .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 mincore
+ {
+ [DllImport(Libraries.Handle, SetLastError = true)]
+ [return: MarshalAs(UnmanagedType.Bool)]
+ internal static extern bool CloseHandle(IntPtr handle);
+ }
+}
diff --git a/src/mscorlib/corefx/Interop/Windows/mincore/Interop.CreateFile.cs b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.CreateFile.cs
new file mode 100644
index 0000000000..670037d52e
--- /dev/null
+++ b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.CreateFile.cs
@@ -0,0 +1,40 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// 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 partial class Interop
+{
+ internal partial class mincore
+ {
+ /// <summary>
+ /// WARNING: This method does not implicitly handle long paths. Use CreateFile.
+ /// </summary>
+ [DllImport(Libraries.CoreFile_L1, EntryPoint = "CreateFileW", SetLastError = true, CharSet = CharSet.Unicode, BestFitMapping = false)]
+ private static extern SafeFileHandle CreateFilePrivate(
+ string lpFileName,
+ int dwDesiredAccess,
+ System.IO.FileShare dwShareMode,
+ [In] ref SECURITY_ATTRIBUTES securityAttrs,
+ System.IO.FileMode dwCreationDisposition,
+ int dwFlagsAndAttributes,
+ IntPtr hTemplateFile);
+
+ internal static SafeFileHandle CreateFile(
+ string lpFileName,
+ int dwDesiredAccess,
+ System.IO.FileShare dwShareMode,
+ [In] ref SECURITY_ATTRIBUTES securityAttrs,
+ System.IO.FileMode dwCreationDisposition,
+ int dwFlagsAndAttributes,
+ IntPtr hTemplateFile)
+ {
+ lpFileName = PathInternal.EnsureExtendedPrefixOverMaxPath(lpFileName);
+ return CreateFilePrivate(lpFileName, dwDesiredAccess, dwShareMode, ref securityAttrs, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile);
+ }
+ }
+}
diff --git a/src/mscorlib/corefx/Interop/Windows/mincore/Interop.Errors.cs b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.Errors.cs
new file mode 100644
index 0000000000..05b2250830
--- /dev/null
+++ b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.Errors.cs
@@ -0,0 +1,74 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+internal partial class Interop
+{
+ internal partial class mincore
+ {
+ internal partial class Errors
+ {
+ internal const int ERROR_SUCCESS = 0x0;
+ internal const int ERROR_INVALID_FUNCTION = 0x1;
+ 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_DATA = 0xD;
+ 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_BAD_LENGTH = 0x18;
+ internal const int ERROR_SHARING_VIOLATION = 0x20;
+ internal const int ERROR_LOCK_VIOLATION = 0x21;
+ internal const int ERROR_HANDLE_EOF = 0x26;
+ 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_NEGATIVE_SEEK = 0x83;
+ internal const int ERROR_DIR_NOT_EMPTY = 0x91;
+ internal const int ERROR_BAD_PATHNAME = 0xA1;
+ internal const int ERROR_LOCK_FAILED = 0xA7;
+ internal const int ERROR_BUSY = 0xAA;
+ internal const int ERROR_ALREADY_EXISTS = 0xB7;
+ internal const int ERROR_BAD_EXE_FORMAT = 0xC1;
+ internal const int ERROR_ENVVAR_NOT_FOUND = 0xCB;
+ internal const int ERROR_FILENAME_EXCED_RANGE = 0xCE;
+ internal const int ERROR_EXE_MACHINE_TYPE_MISMATCH = 0xD8;
+ internal const int ERROR_PIPE_BUSY = 0xE7;
+ internal const int ERROR_NO_DATA = 0xE8;
+ internal const int ERROR_PIPE_NOT_CONNECTED = 0xE9;
+ internal const int ERROR_MORE_DATA = 0xEA;
+ internal const int ERROR_NO_MORE_ITEMS = 0x103;
+ internal const int ERROR_PARTIAL_COPY = 0x12B;
+ internal const int ERROR_ARITHMETIC_OVERFLOW = 0x216;
+ internal const int ERROR_PIPE_CONNECTED = 0x217;
+ internal const int ERROR_PIPE_LISTENING = 0x218;
+ internal const int ERROR_OPERATION_ABORTED = 0x3E3;
+ internal const int ERROR_IO_PENDING = 0x3E5;
+ internal const int ERROR_NO_TOKEN = 0x3f0;
+ internal const int ERROR_DLL_INIT_FAILED = 0x45A;
+ internal const int ERROR_NOT_FOUND = 0x490;
+ internal const int ERROR_NON_ACCOUNT_SID = 0x4E9;
+ internal const int ERROR_NOT_ALL_ASSIGNED = 0x514;
+ internal const int ERROR_UNKNOWN_REVISION = 0x519;
+ internal const int ERROR_INVALID_OWNER = 0x51B;
+ internal const int ERROR_INVALID_PRIMARY_GROUP = 0x51C;
+ internal const int ERROR_NO_SUCH_PRIVILEGE = 0x521;
+ internal const int ERROR_PRIVILEGE_NOT_HELD = 0x522;
+ internal const int ERROR_INVALID_ACL = 0x538;
+ internal const int ERROR_INVALID_SECURITY_DESCR = 0x53A;
+ internal const int ERROR_INVALID_SID = 0x539;
+ internal const int ERROR_BAD_IMPERSONATION_LEVEL = 0x542;
+ internal const int ERROR_CANT_OPEN_ANONYMOUS = 0x543;
+ internal const int ERROR_NO_SECURITY_ON_OBJECT = 0x546;
+ internal const int ERROR_TRUSTED_RELATIONSHIP_FAILURE = 0x6FD;
+ internal const int ERROR_RESOURCE_LANG_NOT_FOUND = 0x717;
+ internal const int EFail = unchecked((int)0x80004005);
+ internal const int E_FILENOTFOUND = unchecked((int)0x80070002);
+ }
+ }
+}
diff --git a/src/mscorlib/corefx/Interop/Windows/mincore/Interop.FileOperations.cs b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.FileOperations.cs
new file mode 100644
index 0000000000..4369760042
--- /dev/null
+++ b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.FileOperations.cs
@@ -0,0 +1,35 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+internal partial class Interop
+{
+ internal partial class mincore
+ {
+ internal partial class IOReparseOptions
+ {
+ internal const uint IO_REPARSE_TAG_FILE_PLACEHOLDER = 0x80000015;
+ internal const uint IO_REPARSE_TAG_MOUNT_POINT = 0xA0000003;
+ }
+
+ internal partial class FileOperations
+ {
+ internal const int OPEN_EXISTING = 3;
+ internal const int COPY_FILE_FAIL_IF_EXISTS = 0x00000001;
+
+ internal const int FILE_ACTION_ADDED = 1;
+ internal const int FILE_ACTION_REMOVED = 2;
+ internal const int FILE_ACTION_MODIFIED = 3;
+ internal const int FILE_ACTION_RENAMED_OLD_NAME = 4;
+ internal const int FILE_ACTION_RENAMED_NEW_NAME = 5;
+
+ internal const int FILE_FLAG_BACKUP_SEMANTICS = 0x02000000;
+ internal const int FILE_FLAG_FIRST_PIPE_INSTANCE = 0x00080000;
+ internal const int FILE_FLAG_OVERLAPPED = 0x40000000;
+
+ internal const int FILE_LIST_DIRECTORY = 0x0001;
+ }
+
+ internal const uint SEM_FAILCRITICALERRORS = 1;
+ }
+}
diff --git a/src/mscorlib/corefx/Interop/Windows/mincore/Interop.FileTypes.cs b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.FileTypes.cs
new file mode 100644
index 0000000000..a24813e8d6
--- /dev/null
+++ b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.FileTypes.cs
@@ -0,0 +1,16 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+internal partial class Interop
+{
+ internal partial class mincore
+ {
+ internal partial class FileTypes
+ {
+ internal const int FILE_TYPE_DISK = 0x0001;
+ internal const int FILE_TYPE_CHAR = 0x0002;
+ internal const int FILE_TYPE_PIPE = 0x0003;
+ }
+ }
+}
diff --git a/src/mscorlib/corefx/Interop/Windows/mincore/Interop.FlushFileBuffers.cs b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.FlushFileBuffers.cs
new file mode 100644
index 0000000000..69f4fe07ce
--- /dev/null
+++ b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.FlushFileBuffers.cs
@@ -0,0 +1,17 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using Microsoft.Win32.SafeHandles;
+using System;
+using System.Runtime.InteropServices;
+
+internal partial class Interop
+{
+ internal partial class mincore
+ {
+ [DllImport(Libraries.CoreFile_L1, SetLastError = true)]
+ [return: MarshalAs(UnmanagedType.Bool)]
+ internal static extern bool FlushFileBuffers(SafeHandle hHandle);
+ }
+}
diff --git a/src/mscorlib/corefx/Interop/Windows/mincore/Interop.FormatMessage.cs b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.FormatMessage.cs
new file mode 100644
index 0000000000..02ecbb8a63
--- /dev/null
+++ b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.FormatMessage.cs
@@ -0,0 +1,112 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .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.Text;
+using System.Runtime.InteropServices;
+
+internal partial class Interop
+{
+ internal partial class mincore
+ {
+ 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 ERROR_INSUFFICIENT_BUFFER = 0x7A;
+
+ [DllImport(Libraries.Localization, CharSet = CharSet.Unicode, EntryPoint = "FormatMessageW", SetLastError = true, BestFitMapping = true)]
+ private static extern int FormatMessage(
+ int dwFlags,
+ IntPtr lpSource,
+ uint dwMessageId,
+ int dwLanguageId,
+ [Out] StringBuilder lpBuffer,
+ int nSize,
+ IntPtr[] arguments);
+
+ /// <summary>
+ /// Returns a string message for the specified Win32 error code.
+ /// </summary>
+ internal static string GetMessage(int errorCode)
+ {
+ return GetMessage(IntPtr.Zero, errorCode);
+ }
+
+ internal static string GetMessage(IntPtr moduleHandle, int errorCode)
+ {
+ var sb = new StringBuilder(InitialBufferSize);
+ do
+ {
+ string errorMsg;
+ if (TryGetErrorMessage(moduleHandle, errorCode, sb, out errorMsg))
+ {
+ return errorMsg;
+ }
+ else
+ {
+ // increase the capacity of the StringBuilder.
+ sb.Capacity *= BufferSizeIncreaseFactor;
+ }
+ }
+ while (sb.Capacity < MaxAllowedBufferSize);
+
+ // If you come here then a size as large as 65K is also not sufficient and so we give the generic errorMsg.
+ return string.Format("Unknown error (0x{0:x})", errorCode);
+ }
+
+ private static bool TryGetErrorMessage(IntPtr moduleHandle, int errorCode, StringBuilder sb, out string errorMsg)
+ {
+ errorMsg = "";
+
+ int flags = FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ARGUMENT_ARRAY;
+ if (moduleHandle != IntPtr.Zero)
+ {
+ flags |= FORMAT_MESSAGE_FROM_HMODULE;
+ }
+
+ int result = FormatMessage(flags, moduleHandle, (uint)errorCode, 0, sb, sb.Capacity, null);
+ if (result != 0)
+ {
+ int i = sb.Length;
+ while (i > 0)
+ {
+ char ch = sb[i - 1];
+ if (ch > 32 && ch != '.') break;
+ i--;
+ }
+ errorMsg = sb.ToString(0, i);
+ }
+ else if (Marshal.GetLastWin32Error() == ERROR_INSUFFICIENT_BUFFER)
+ {
+ return false;
+ }
+ else
+ {
+ errorMsg = string.Format("Unknown error (0x{0:x})", errorCode);
+ }
+
+ return true;
+ }
+
+ // Windows API FormatMessage lets you format a message string given an errorcode.
+ // Unlike other APIs this API does not support a way to query it for the total message size.
+ //
+ // So the API can only be used in one of these two ways.
+ // a. You pass a buffer of appropriate size and get the resource.
+ // b. Windows creates a buffer and passes the address back and the onus of releasing the buffer lies on the caller.
+ //
+ // Since the error code is coming from the user, it is not possible to know the size in advance.
+ // Unfortunately we can't use option b. since the buffer can only be freed using LocalFree and it is a private API on onecore.
+ // Also, using option b is ugly for the managed code and could cause memory leak in situations where freeing is unsuccessful.
+ //
+ // As a result we use the following approach.
+ // We initially call the API with a buffer size of 256 and then gradually increase the size in case of failure until we reach the maximum allowed limit of 65K.
+ private const int InitialBufferSize = 256;
+ private const int BufferSizeIncreaseFactor = 4;
+ private const int MaxAllowedBufferSize = 65 * 1024;
+ }
+}
diff --git a/src/mscorlib/corefx/Interop/Windows/mincore/Interop.GetFileInformationByHandleEx.cs b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.GetFileInformationByHandleEx.cs
new file mode 100644
index 0000000000..c4739a5ddc
--- /dev/null
+++ b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.GetFileInformationByHandleEx.cs
@@ -0,0 +1,26 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using Microsoft.Win32.SafeHandles;
+using System;
+using System.Runtime.InteropServices;
+
+internal partial class Interop
+{
+ internal partial class mincore
+ {
+ [DllImport(Libraries.CoreFile_L2, SetLastError = true)]
+ internal static extern bool GetFileInformationByHandleEx(SafeFileHandle hFile, FILE_INFO_BY_HANDLE_CLASS FileInformationClass, out FILE_STANDARD_INFO lpFileInformation, uint dwBufferSize);
+
+ internal partial struct FILE_STANDARD_INFO
+ {
+ internal long AllocationSize;
+ internal long EndOfFile;
+ internal uint NumberOfLinks;
+ internal BOOL DeletePending;
+ internal BOOL Directory;
+ }
+
+ }
+}
diff --git a/src/mscorlib/corefx/Interop/Windows/mincore/Interop.GetFileType_SafeHandle.cs b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.GetFileType_SafeHandle.cs
new file mode 100644
index 0000000000..3e2567b6bf
--- /dev/null
+++ b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.GetFileType_SafeHandle.cs
@@ -0,0 +1,15 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using Microsoft.Win32.SafeHandles;
+using System.Runtime.InteropServices;
+
+internal partial class Interop
+{
+ internal partial class mincore
+ {
+ [DllImport(Libraries.CoreFile_L1, SetLastError = true)]
+ internal extern static int GetFileType(SafeHandle hFile);
+ }
+}
diff --git a/src/mscorlib/corefx/Interop/Windows/mincore/Interop.GetFullPathNameW.cs b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.GetFullPathNameW.cs
new file mode 100644
index 0000000000..a34cc33db3
--- /dev/null
+++ b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.GetFullPathNameW.cs
@@ -0,0 +1,18 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Runtime.InteropServices;
+
+internal partial class Interop
+{
+ internal partial class mincore
+ {
+ /// <summary>
+ /// WARNING: This method does not implicitly handle long paths. Use GetFullPathName or PathHelper.
+ /// </summary>
+ [DllImport(Libraries.CoreFile_L1, SetLastError = true, CharSet = CharSet.Unicode, BestFitMapping = false, ExactSpelling = true)]
+ unsafe internal static extern uint GetFullPathNameW(char* path, uint numBufferChars, SafeHandle buffer, IntPtr mustBeZero);
+ }
+}
diff --git a/src/mscorlib/corefx/Interop/Windows/mincore/Interop.GetLongPathNameW.cs b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.GetLongPathNameW.cs
new file mode 100644
index 0000000000..d50db6650b
--- /dev/null
+++ b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.GetLongPathNameW.cs
@@ -0,0 +1,18 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Runtime.InteropServices;
+
+partial class Interop
+{
+ partial class mincore
+ {
+ /// <summary>
+ /// WARNING: This method does not implicitly handle long paths. Use GetFullPath/PathHelper.
+ /// </summary>
+ [DllImport(Libraries.CoreFile_L1, SetLastError = true, CharSet = CharSet.Unicode, BestFitMapping = false, ExactSpelling = true)]
+ internal static extern uint GetLongPathNameW(SafeHandle lpszShortPath, SafeHandle lpszLongPath, uint cchBuffer);
+ }
+}
diff --git a/src/mscorlib/corefx/Interop/Windows/mincore/Interop.GetTempFileNameW.cs b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.GetTempFileNameW.cs
new file mode 100644
index 0000000000..f06d11be52
--- /dev/null
+++ b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.GetTempFileNameW.cs
@@ -0,0 +1,16 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .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.Text;
+using System.Runtime.InteropServices;
+
+partial class Interop
+{
+ partial class mincore
+ {
+ [DllImport(Libraries.CoreFile_L1, CharSet = CharSet.Unicode, SetLastError = true, BestFitMapping = false)]
+ internal static extern uint GetTempFileNameW(string tmpPath, string prefix, uint uniqueIdOrZero, [Out]StringBuilder tmpFileName);
+ }
+}
diff --git a/src/mscorlib/corefx/Interop/Windows/mincore/Interop.GetTempPathW.cs b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.GetTempPathW.cs
new file mode 100644
index 0000000000..0ccc27c9ec
--- /dev/null
+++ b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.GetTempPathW.cs
@@ -0,0 +1,16 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .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.Runtime.InteropServices;
+
+partial class Interop
+{
+ partial class mincore
+ {
+ [DllImport(Libraries.CoreFile_L1_2, CharSet = CharSet.Unicode, BestFitMapping = false)]
+ internal static extern uint GetTempPathW(int bufferLen, [Out]StringBuilder buffer);
+ }
+}
diff --git a/src/mscorlib/corefx/Interop/Windows/mincore/Interop.Idna.cs b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.Idna.cs
new file mode 100644
index 0000000000..e14f16b048
--- /dev/null
+++ b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.Idna.cs
@@ -0,0 +1,37 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .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 mincore
+ {
+ //
+ // Idn APIs
+ //
+
+ [DllImport("api-ms-win-core-localization-l1-2-0.dll", CharSet = CharSet.Unicode, SetLastError = true)]
+ internal static extern int IdnToAscii(
+ uint dwFlags,
+ IntPtr lpUnicodeCharStr,
+ int cchUnicodeChar,
+ [System.Runtime.InteropServices.OutAttribute()]
+ IntPtr lpASCIICharStr,
+ int cchASCIIChar);
+
+ [DllImport("api-ms-win-core-localization-l1-2-0.dll", CharSet = CharSet.Unicode, SetLastError = true)]
+ internal static extern int IdnToUnicode(
+ uint dwFlags,
+ IntPtr lpASCIICharStr,
+ int cchASCIIChar,
+ [System.Runtime.InteropServices.OutAttribute()]
+ IntPtr lpUnicodeCharStr,
+ int cchUnicodeChar);
+
+ internal const int IDN_ALLOW_UNASSIGNED = 0x1;
+ internal const int IDN_USE_STD3_ASCII_RULES = 0x2;
+ }
+}
diff --git a/src/mscorlib/corefx/Interop/Windows/mincore/Interop.LockFile.cs b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.LockFile.cs
new file mode 100644
index 0000000000..ee9a98ecce
--- /dev/null
+++ b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.LockFile.cs
@@ -0,0 +1,20 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// 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 partial class Interop
+{
+ internal partial class mincore
+ {
+ [DllImport(Libraries.CoreFile_L1, SetLastError = true)]
+ internal static extern bool LockFile(SafeFileHandle handle, int offsetLow, int offsetHigh, int countLow, int countHigh);
+
+ [DllImport(Libraries.CoreFile_L1, SetLastError = true)]
+ internal static extern bool UnlockFile(SafeFileHandle handle, int offsetLow, int offsetHigh, int countLow, int countHigh);
+ }
+}
diff --git a/src/mscorlib/corefx/Interop/Windows/mincore/Interop.ReadFile_SafeHandle_IntPtr.cs b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.ReadFile_SafeHandle_IntPtr.cs
new file mode 100644
index 0000000000..093a993c10
--- /dev/null
+++ b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.ReadFile_SafeHandle_IntPtr.cs
@@ -0,0 +1,21 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using Microsoft.Win32.SafeHandles;
+using System;
+using System.Runtime.InteropServices;
+
+internal partial class Interop
+{
+ internal partial class mincore
+ {
+ [DllImport(Libraries.CoreFile_L1, SetLastError = true)]
+ unsafe internal static extern int ReadFile(
+ SafeHandle handle,
+ byte* bytes,
+ int numBytesToRead,
+ out int numBytesRead,
+ IntPtr mustBeZero);
+ }
+}
diff --git a/src/mscorlib/corefx/Interop/Windows/mincore/Interop.ReadFile_SafeHandle_NativeOverlapped.cs b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.ReadFile_SafeHandle_NativeOverlapped.cs
new file mode 100644
index 0000000000..ac238cb802
--- /dev/null
+++ b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.ReadFile_SafeHandle_NativeOverlapped.cs
@@ -0,0 +1,22 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// 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;
+using System.Threading;
+
+internal partial class Interop
+{
+ internal partial class mincore
+ {
+ [DllImport(Libraries.CoreFile_L1, SetLastError = true)]
+ unsafe internal static extern int ReadFile(
+ SafeHandle handle,
+ byte* bytes,
+ int numBytesToRead,
+ IntPtr numBytesRead_mustBeZero,
+ NativeOverlapped* overlapped);
+ }
+}
diff --git a/src/mscorlib/corefx/Interop/Windows/mincore/Interop.SECURITY_ATTRIBUTES.cs b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.SECURITY_ATTRIBUTES.cs
new file mode 100644
index 0000000000..0f5c224022
--- /dev/null
+++ b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.SECURITY_ATTRIBUTES.cs
@@ -0,0 +1,21 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using Microsoft.Win32.SafeHandles;
+using System;
+using System.Runtime.InteropServices;
+
+internal partial class Interop
+{
+ internal partial class mincore
+ {
+ [StructLayout(LayoutKind.Sequential)]
+ internal struct SECURITY_ATTRIBUTES
+ {
+ internal uint nLength;
+ internal IntPtr lpSecurityDescriptor;
+ internal BOOL bInheritHandle;
+ }
+ }
+}
diff --git a/src/mscorlib/corefx/Interop/Windows/mincore/Interop.SafeCreateFile.cs b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.SafeCreateFile.cs
new file mode 100644
index 0000000000..edfc66d2c9
--- /dev/null
+++ b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.SafeCreateFile.cs
@@ -0,0 +1,45 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .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.IO;
+using System.Runtime.InteropServices;
+using Microsoft.Win32.SafeHandles;
+
+internal partial class Interop
+{
+ internal partial class mincore
+ {
+ internal static readonly IntPtr INVALID_HANDLE_VALUE = new IntPtr(-1); // WinBase.h
+
+ /// <summary>
+ /// Does not allow access to non-file devices. This disallows DOS devices like "con:", "com1:",
+ /// "lpt1:", etc. Use this to avoid security problems, like allowing a web client asking a server
+ /// for "http://server/com1.aspx" and then causing a worker process to hang.
+ /// </summary>
+ internal static SafeFileHandle SafeCreateFile(
+ String lpFileName,
+ int dwDesiredAccess,
+ System.IO.FileShare dwShareMode,
+ ref Interop.mincore.SECURITY_ATTRIBUTES securityAttrs,
+ FileMode dwCreationDisposition,
+ int dwFlagsAndAttributes,
+ IntPtr hTemplateFile)
+ {
+ SafeFileHandle handle = UnsafeCreateFile(lpFileName, dwDesiredAccess, dwShareMode, ref securityAttrs, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile);
+
+ if (!handle.IsInvalid)
+ {
+ int fileType = Interop.mincore.GetFileType(handle);
+ if (fileType != Interop.mincore.FileTypes.FILE_TYPE_DISK)
+ {
+ handle.Dispose();
+ throw new NotSupportedException(SR.NotSupported_FileStreamOnNonFiles);
+ }
+ }
+
+ return handle;
+ }
+ }
+}
diff --git a/src/mscorlib/corefx/Interop/Windows/mincore/Interop.SecurityOptions.cs b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.SecurityOptions.cs
new file mode 100644
index 0000000000..767d7f528f
--- /dev/null
+++ b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.SecurityOptions.cs
@@ -0,0 +1,18 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+internal partial class Interop
+{
+ internal partial class mincore
+ {
+ internal 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/src/mscorlib/corefx/Interop/Windows/mincore/Interop.SetEndOfFile.cs b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.SetEndOfFile.cs
new file mode 100644
index 0000000000..ee0d3b4bc8
--- /dev/null
+++ b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.SetEndOfFile.cs
@@ -0,0 +1,15 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using Microsoft.Win32.SafeHandles;
+using System.Runtime.InteropServices;
+
+internal partial class Interop
+{
+ internal partial class mincore
+ {
+ [DllImport(Libraries.CoreFile_L1, SetLastError = true)]
+ internal static extern bool SetEndOfFile(SafeFileHandle hFile);
+ }
+}
diff --git a/src/mscorlib/corefx/Interop/Windows/mincore/Interop.SetErrorMode.cs b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.SetErrorMode.cs
new file mode 100644
index 0000000000..a845990ded
--- /dev/null
+++ b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.SetErrorMode.cs
@@ -0,0 +1,14 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System.Runtime.InteropServices;
+
+internal partial class Interop
+{
+ internal partial class mincore
+ {
+ [DllImport(Libraries.ErrorHandling, SetLastError = false, EntryPoint = "SetErrorMode", ExactSpelling = true)]
+ internal static extern uint SetErrorMode(uint newMode);
+ }
+}
diff --git a/src/mscorlib/corefx/Interop/Windows/mincore/Interop.SetFileInformationByHandle.cs b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.SetFileInformationByHandle.cs
new file mode 100644
index 0000000000..0519219132
--- /dev/null
+++ b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.SetFileInformationByHandle.cs
@@ -0,0 +1,72 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using Microsoft.Win32.SafeHandles;
+using System;
+using System.Runtime.InteropServices;
+
+internal partial class Interop
+{
+ internal partial class mincore
+ {
+ [DllImport(Libraries.CoreFile_L1, SetLastError = true)]
+ internal static extern bool SetFileInformationByHandle(SafeFileHandle hFile, FILE_INFO_BY_HANDLE_CLASS FileInformationClass, ref FILE_BASIC_INFO lpFileInformation, uint dwBufferSize);
+
+ // Default values indicate "no change". Use defaults so that we don't force callsites to be aware of the default values
+ internal unsafe static bool SetFileTime(
+ SafeFileHandle hFile,
+ long creationTime = -1,
+ long lastAccessTime = -1,
+ long lastWriteTime = -1,
+ long changeTime = -1,
+ uint fileAttributes = 0)
+ {
+ FILE_BASIC_INFO basicInfo = new FILE_BASIC_INFO()
+ {
+ CreationTime = creationTime,
+ LastAccessTime = lastAccessTime,
+ LastWriteTime = lastWriteTime,
+ ChangeTime = changeTime,
+ FileAttributes = fileAttributes
+ };
+
+ return SetFileInformationByHandle(hFile, FILE_INFO_BY_HANDLE_CLASS.FileBasicInfo, ref basicInfo, (uint)Marshal.SizeOf<FILE_BASIC_INFO>());
+ }
+
+ internal struct FILE_BASIC_INFO
+ {
+ internal long CreationTime;
+ internal long LastAccessTime;
+ internal long LastWriteTime;
+ internal long ChangeTime;
+ internal uint FileAttributes;
+ }
+
+ 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/src/mscorlib/corefx/Interop/Windows/mincore/Interop.SetFilePointerEx.cs b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.SetFilePointerEx.cs
new file mode 100644
index 0000000000..09f8e1feb3
--- /dev/null
+++ b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.SetFilePointerEx.cs
@@ -0,0 +1,15 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using Microsoft.Win32.SafeHandles;
+using System.Runtime.InteropServices;
+
+internal partial class Interop
+{
+ internal partial class mincore
+ {
+ [DllImport(Libraries.CoreFile_L1, SetLastError = true)]
+ internal static extern bool SetFilePointerEx(SafeFileHandle hFile, long liDistanceToMove, out long lpNewFilePointer, uint dwMoveMethod);
+ }
+}
diff --git a/src/mscorlib/corefx/Interop/Windows/mincore/Interop.ThreadPoolIO.cs b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.ThreadPoolIO.cs
new file mode 100644
index 0000000000..a0afed5d1a
--- /dev/null
+++ b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.ThreadPoolIO.cs
@@ -0,0 +1,27 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Runtime.InteropServices;
+using Microsoft.Win32.SafeHandles;
+
+internal static partial class Interop
+{
+ internal static partial class mincore
+ {
+ [DllImport(Libraries.ThreadPool, SetLastError = true)]
+ internal static unsafe extern SafeThreadPoolIOHandle CreateThreadpoolIo(SafeHandle fl, [MarshalAs(UnmanagedType.FunctionPtr)] NativeIoCompletionCallback pfnio, IntPtr context, IntPtr pcbe);
+
+ [DllImport(Libraries.ThreadPool)]
+ internal static unsafe extern void CloseThreadpoolIo(IntPtr pio);
+
+ [DllImport(Libraries.ThreadPool)]
+ internal static unsafe extern void StartThreadpoolIo(SafeThreadPoolIOHandle pio);
+
+ [DllImport(Libraries.ThreadPool)]
+ internal static unsafe extern void CancelThreadpoolIo(SafeThreadPoolIOHandle pio);
+ }
+
+ internal delegate void NativeIoCompletionCallback(IntPtr instance, IntPtr context, IntPtr overlapped, uint ioResult, UIntPtr numberOfBytesTransferred, IntPtr io);
+}
diff --git a/src/mscorlib/corefx/Interop/Windows/mincore/Interop.UnsafeCreateFile.cs b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.UnsafeCreateFile.cs
new file mode 100644
index 0000000000..e7e4f0513a
--- /dev/null
+++ b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.UnsafeCreateFile.cs
@@ -0,0 +1,25 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .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.IO;
+using Microsoft.Win32.SafeHandles;
+
+internal partial class Interop
+{
+ internal partial class mincore
+ {
+ internal static SafeFileHandle UnsafeCreateFile(
+ string lpFileName,
+ int dwDesiredAccess,
+ FileShare dwShareMode,
+ ref Interop.mincore.SECURITY_ATTRIBUTES securityAttrs,
+ FileMode dwCreationDisposition,
+ int dwFlagsAndAttributes,
+ IntPtr hTemplateFile)
+ {
+ return CreateFile(lpFileName, dwDesiredAccess, dwShareMode, ref securityAttrs, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile);
+ }
+ }
+}
diff --git a/src/mscorlib/corefx/Interop/Windows/mincore/Interop.WideCharToMultiByte.cs b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.WideCharToMultiByte.cs
new file mode 100644
index 0000000000..b1a2975696
--- /dev/null
+++ b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.WideCharToMultiByte.cs
@@ -0,0 +1,22 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .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 mincore
+ {
+ [DllImport(Libraries.String_L1)]
+ 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/src/mscorlib/corefx/Interop/Windows/mincore/Interop.WriteFile_SafeHandle_IntPtr.cs b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.WriteFile_SafeHandle_IntPtr.cs
new file mode 100644
index 0000000000..052ba3ce7d
--- /dev/null
+++ b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.WriteFile_SafeHandle_IntPtr.cs
@@ -0,0 +1,24 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using Microsoft.Win32.SafeHandles;
+using System;
+using System.Runtime.InteropServices;
+
+internal partial class Interop
+{
+ internal partial class mincore
+ {
+ // 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.CoreFile_L1, SetLastError = true)]
+ internal static unsafe extern int WriteFile(SafeHandle handle, byte* bytes, int numBytesToWrite, out int numBytesWritten, IntPtr mustBeZero);
+
+ }
+}
diff --git a/src/mscorlib/corefx/Interop/Windows/mincore/Interop.WriteFile_SafeHandle_NativeOverlapped.cs b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.WriteFile_SafeHandle_NativeOverlapped.cs
new file mode 100644
index 0000000000..e9d2953045
--- /dev/null
+++ b/src/mscorlib/corefx/Interop/Windows/mincore/Interop.WriteFile_SafeHandle_NativeOverlapped.cs
@@ -0,0 +1,22 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// 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;
+using System.Threading;
+internal partial class Interop
+{
+ internal partial class mincore
+ {
+ // 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.CoreFile_L1, SetLastError = true)]
+ internal static unsafe extern int WriteFile(SafeHandle handle, byte* bytes, int numBytesToWrite, IntPtr numBytesWritten_mustBeZero, NativeOverlapped* lpOverlapped);
+ }
+}
diff --git a/src/mscorlib/corefx/Interop/Windows/oleaut32/Interop.SysAllocStringLen.cs b/src/mscorlib/corefx/Interop/Windows/oleaut32/Interop.SysAllocStringLen.cs
new file mode 100644
index 0000000000..65da4eaaea
--- /dev/null
+++ b/src/mscorlib/corefx/Interop/Windows/oleaut32/Interop.SysAllocStringLen.cs
@@ -0,0 +1,16 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .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 partial class Interop
+{
+ internal partial class OleAut32
+ {
+ [DllImport(Libraries.OleAut32, CharSet = CharSet.Unicode)]
+ internal static extern SafeBSTRHandle SysAllocStringLen(IntPtr src, uint len); // BSTR
+ }
+}
diff --git a/src/mscorlib/corefx/Interop/Windows/oleaut32/Interop.SysStringLen.cs b/src/mscorlib/corefx/Interop/Windows/oleaut32/Interop.SysStringLen.cs
new file mode 100644
index 0000000000..027d8eece9
--- /dev/null
+++ b/src/mscorlib/corefx/Interop/Windows/oleaut32/Interop.SysStringLen.cs
@@ -0,0 +1,22 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .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 partial class Interop
+{
+ internal partial class OleAut32
+ {
+ [DllImport(Libraries.OleAut32)]
+ internal static extern uint SysStringLen(SafeBSTRHandle bstr);
+
+ [DllImport(Libraries.OleAut32)]
+ internal static extern uint SysStringLen(IntPtr bstr);
+
+ [DllImport(Libraries.OleAut32)]
+ internal static extern void SysFreeString(IntPtr bstr);
+ }
+}
diff --git a/src/mscorlib/corefx/Microsoft/Win32/SafeHandles/SafeFileHandle.Unix.cs b/src/mscorlib/corefx/Microsoft/Win32/SafeHandles/SafeFileHandle.Unix.cs
new file mode 100644
index 0000000000..5ddb31ad36
--- /dev/null
+++ b/src/mscorlib/corefx/Microsoft/Win32/SafeHandles/SafeFileHandle.Unix.cs
@@ -0,0 +1,122 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .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;
+
+namespace Microsoft.Win32.SafeHandles
+{
+ [System.Security.SecurityCritical]
+ public sealed class SafeFileHandle : SafeHandleZeroOrMinusOneIsInvalid
+ {
+ /// <summary>A handle value of -1.</summary>
+ private static readonly IntPtr s_invalidHandle = new IntPtr(-1);
+
+ private SafeFileHandle() : this(ownsHandle: true)
+ {
+ }
+
+ private SafeFileHandle(bool ownsHandle)
+ : base(ownsHandle)
+ {
+ SetHandle(s_invalidHandle);
+ }
+
+ 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);
+
+ // 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.
+ bool enoentDueToDirectory = (flags & Interop.Sys.OpenFlags.O_CREAT) != 0;
+
+ // Open the file.
+ SafeFileHandle handle = Interop.CheckIo(
+ Interop.Sys.Open(path, flags, mode),
+ path,
+ isDirectory: enoentDueToDirectory,
+ 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;
+ }
+
+ /// <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;
+ }
+
+ [System.Security.SecurityCritical]
+ 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);
+#if DEBUG
+ if (result != 0)
+ {
+ Debug.Fail(string.Format(
+ "Close failed with result {0} and error {1}",
+ result, Interop.Sys.GetLastErrorInfo()));
+ }
+#endif
+ return result == 0;
+ }
+
+ public override bool IsInvalid
+ {
+ [System.Security.SecurityCritical]
+ get
+ {
+ long h = (long)handle;
+ return h < 0 || h > int.MaxValue;
+ }
+ }
+ }
+}
diff --git a/src/mscorlib/corefx/Microsoft/Win32/SafeHandles/SafeFileHandle.Windows.cs b/src/mscorlib/corefx/Microsoft/Win32/SafeHandles/SafeFileHandle.Windows.cs
new file mode 100644
index 0000000000..7d4dd444c7
--- /dev/null
+++ b/src/mscorlib/corefx/Microsoft/Win32/SafeHandles/SafeFileHandle.Windows.cs
@@ -0,0 +1,50 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .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.Security;
+using System.Runtime.InteropServices;
+using System.Threading;
+using Microsoft.Win32;
+
+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
+ {
+ return _isAsync;
+ }
+
+ set
+ {
+ _isAsync = value;
+ }
+ }
+
+ internal ThreadPoolBoundHandle ThreadPoolBinding { get; set; }
+
+ override protected bool ReleaseHandle()
+ {
+ return Interop.mincore.CloseHandle(handle);
+ }
+ }
+}
+
diff --git a/src/mscorlib/corefx/Microsoft/Win32/SafeHandles/SafeThreadPoolIOHandle.cs b/src/mscorlib/corefx/Microsoft/Win32/SafeHandles/SafeThreadPoolIOHandle.cs
new file mode 100644
index 0000000000..3dbc2bb620
--- /dev/null
+++ b/src/mscorlib/corefx/Microsoft/Win32/SafeHandles/SafeThreadPoolIOHandle.cs
@@ -0,0 +1,28 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .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
+{
+ internal class SafeThreadPoolIOHandle : SafeHandle
+ {
+ private SafeThreadPoolIOHandle()
+ : base(IntPtr.Zero, true)
+ {
+ }
+
+ public override bool IsInvalid
+ {
+ get { return handle == IntPtr.Zero; }
+ }
+
+ protected override bool ReleaseHandle()
+ {
+ Interop.mincore.CloseThreadpoolIo(handle);
+ return true;
+ }
+ }
+}
diff --git a/src/mscorlib/corefx/SR.cs b/src/mscorlib/corefx/SR.cs
index 513bd9d94d..d820613f7e 100644
--- a/src/mscorlib/corefx/SR.cs
+++ b/src/mscorlib/corefx/SR.cs
@@ -1,247 +1,588 @@
using System;
+using System.Globalization;
-namespace System.Globalization
+// CoreFX creates SR in the System namespace. While putting the CoreCLR SR adapter in the root
+// may be unconventional, it allows us to keep the shared code identical.
+
+internal static class SR
{
- internal static class SR
- {
- public static string Arg_HexStyleNotSupported
- {
- get { return Environment.GetResourceString("Arg_HexStyleNotSupported"); }
- }
-
- public static string Arg_InvalidHexStyle
- {
- get { return Environment.GetResourceString("Arg_InvalidHexStyle"); }
- }
-
- public static string ArgumentNull_Array
- {
- get { return Environment.GetResourceString("ArgumentNull_Array"); }
- }
-
- public static string ArgumentNull_ArrayValue
- {
- get { return Environment.GetResourceString("ArgumentNull_ArrayValue"); }
- }
-
- public static string ArgumentNull_Obj
- {
- get { return Environment.GetResourceString("ArgumentNull_Obj"); }
- }
-
- public static string ArgumentNull_String
- {
- get { return Environment.GetResourceString("ArgumentNull_String"); }
- }
-
- public static string ArgumentOutOfRange_AddValue
- {
- get { return Environment.GetResourceString("ArgumentOutOfRange_AddValue"); }
- }
-
- public static string ArgumentOutOfRange_BadHourMinuteSecond
- {
- get { return Environment.GetResourceString("ArgumentOutOfRange_BadHourMinuteSecond"); }
- }
-
- public static string ArgumentOutOfRange_BadYearMonthDay
- {
- get { return Environment.GetResourceString("ArgumentOutOfRange_BadYearMonthDay"); }
- }
-
- public static string ArgumentOutOfRange_Bounds_Lower_Upper
- {
- get { return Environment.GetResourceString("ArgumentOutOfRange_Bounds_Lower_Upper"); }
- }
-
- public static string ArgumentOutOfRange_CalendarRange
- {
- get { return Environment.GetResourceString("ArgumentOutOfRange_CalendarRange"); }
- }
-
- public static string ArgumentOutOfRange_Count
- {
- get { return Environment.GetResourceString("ArgumentOutOfRange_Count"); }
- }
-
- public static string ArgumentOutOfRange_Day
- {
- get { return Environment.GetResourceString("ArgumentOutOfRange_Day"); }
- }
-
- public static string ArgumentOutOfRange_Enum
- {
- get { return Environment.GetResourceString("ArgumentOutOfRange_Enum"); }
- }
-
- public static string ArgumentOutOfRange_Era
- {
- get { return Environment.GetResourceString("ArgumentOutOfRange_Era"); }
- }
-
- public static string ArgumentOutOfRange_Index
- {
- get { return Environment.GetResourceString("ArgumentOutOfRange_Index"); }
- }
-
- public static string ArgumentOutOfRange_InvalidEraValue
- {
- get { return Environment.GetResourceString("ArgumentOutOfRange_InvalidEraValue"); }
- }
-
- public static string ArgumentOutOfRange_Month
- {
- get { return Environment.GetResourceString("ArgumentOutOfRange_Month"); }
- }
-
- public static string ArgumentOutOfRange_NeedNonNegNum
- {
- get { return Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"); }
- }
-
- public static string ArgumentOutOfRange_NeedPosNum
- {
- get { return Environment.GetResourceString("ArgumentOutOfRange_NeedPosNum"); }
- }
-
- public static string ArgumentOutOfRange_OffsetLength
- {
- get { return Environment.GetResourceString("ArgumentOutOfRange_OffsetLength"); }
- }
-
- public static string ArgumentOutOfRange_Range
- {
- get { return Environment.GetResourceString("ArgumentOutOfRange_Range"); }
- }
-
- public static string Argument_CompareOptionOrdinal
- {
- get { return Environment.GetResourceString("Argument_CompareOptionOrdinal"); }
- }
-
- public static string Argument_ConflictingDateTimeRoundtripStyles
- {
- get { return Environment.GetResourceString("Argument_ConflictingDateTimeRoundtripStyles"); }
- }
-
- public static string Argument_ConflictingDateTimeStyles
- {
- get { return Environment.GetResourceString("Argument_ConflictingDateTimeStyles"); }
- }
-
- public static string Argument_CultureInvalidIdentifier
- {
- get { return Environment.GetResourceString("Argument_CultureInvalidIdentifier"); }
- }
-
- public static string Argument_CultureNotSupported
- {
- get { return Environment.GetResourceString("Argument_CultureNotSupported"); }
- }
+ public static string Arg_ArrayZeroError
+ {
+ get { return Environment.GetResourceString("Arg_ArrayZeroError"); }
+ }
+
+ public static string Arg_ExternalException
+ {
+ get { return Environment.GetResourceString("Arg_ExternalException"); }
+ }
+
+ public static string Arg_HexStyleNotSupported
+ {
+ get { return Environment.GetResourceString("Arg_HexStyleNotSupported"); }
+ }
+
+ public static string Arg_InvalidHexStyle
+ {
+ get { return Environment.GetResourceString("Arg_InvalidHexStyle"); }
+ }
+
+ public static string ArgumentNull_Array
+ {
+ get { return Environment.GetResourceString("ArgumentNull_Array"); }
+ }
+
+ public static string ArgumentNull_ArrayValue
+ {
+ get { return Environment.GetResourceString("ArgumentNull_ArrayValue"); }
+ }
+
+ public static string ArgumentNull_Obj
+ {
+ get { return Environment.GetResourceString("ArgumentNull_Obj"); }
+ }
+
+ public static string ArgumentNull_String
+ {
+ get { return Environment.GetResourceString("ArgumentNull_String"); }
+ }
+
+ public static string ArgumentOutOfRange_AddValue
+ {
+ get { return Environment.GetResourceString("ArgumentOutOfRange_AddValue"); }
+ }
+
+ public static string ArgumentOutOfRange_BadHourMinuteSecond
+ {
+ get { return Environment.GetResourceString("ArgumentOutOfRange_BadHourMinuteSecond"); }
+ }
+
+ public static string ArgumentOutOfRange_BadYearMonthDay
+ {
+ get { return Environment.GetResourceString("ArgumentOutOfRange_BadYearMonthDay"); }
+ }
+
+ public static string ArgumentOutOfRange_Bounds_Lower_Upper
+ {
+ get { return Environment.GetResourceString("ArgumentOutOfRange_Bounds_Lower_Upper"); }
+ }
+
+ public static string ArgumentOutOfRange_CalendarRange
+ {
+ get { return Environment.GetResourceString("ArgumentOutOfRange_CalendarRange"); }
+ }
+
+ public static string ArgumentOutOfRange_Count
+ {
+ get { return Environment.GetResourceString("ArgumentOutOfRange_Count"); }
+ }
+
+ public static string ArgumentOutOfRange_Day
+ {
+ get { return Environment.GetResourceString("ArgumentOutOfRange_Day"); }
+ }
+
+ public static string ArgumentOutOfRange_Enum
+ {
+ get { return Environment.GetResourceString("ArgumentOutOfRange_Enum"); }
+ }
+
+ public static string ArgumentOutOfRange_Era
+ {
+ get { return Environment.GetResourceString("ArgumentOutOfRange_Era"); }
+ }
+
+ public static string ArgumentOutOfRange_Index
+ {
+ get { return Environment.GetResourceString("ArgumentOutOfRange_Index"); }
+ }
+
+ public static string ArgumentOutOfRange_IndexCountBuffer
+ {
+ get { return Environment.GetResourceString("ArgumentOutOfRange_IndexCountBuffer"); }
+ }
+
+ public static string ArgumentOutOfRange_InvalidEraValue
+ {
+ get { return Environment.GetResourceString("ArgumentOutOfRange_InvalidEraValue"); }
+ }
+
+ public static string ArgumentOutOfRange_Month
+ {
+ get { return Environment.GetResourceString("ArgumentOutOfRange_Month"); }
+ }
+
+ public static string ArgumentOutOfRange_NeedNonNegNum
+ {
+ get { return Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"); }
+ }
+
+ public static string ArgumentOutOfRange_NeedPosNum
+ {
+ get { return Environment.GetResourceString("ArgumentOutOfRange_NeedPosNum"); }
+ }
+
+ public static string Arg_ArgumentOutOfRangeException
+ {
+ get { return Environment.GetResourceString("Arg_ArgumentOutOfRangeException"); }
+ }
+
+ public static string ArgumentOutOfRange_OffsetLength
+ {
+ get { return Environment.GetResourceString("ArgumentOutOfRange_OffsetLength"); }
+ }
+
+ public static string ArgumentOutOfRange_Range
+ {
+ get { return Environment.GetResourceString("ArgumentOutOfRange_Range"); }
+ }
+
+ public static string Argument_CompareOptionOrdinal
+ {
+ get { return Environment.GetResourceString("Argument_CompareOptionOrdinal"); }
+ }
+
+ public static string Argument_ConflictingDateTimeRoundtripStyles
+ {
+ get { return Environment.GetResourceString("Argument_ConflictingDateTimeRoundtripStyles"); }
+ }
+
+ public static string Argument_ConflictingDateTimeStyles
+ {
+ get { return Environment.GetResourceString("Argument_ConflictingDateTimeStyles"); }
+ }
+
+ public static string Argument_CultureIetfNotSupported
+ {
+ get { return Environment.GetResourceString("Argument_CultureIetfNotSupported"); }
+ }
+
+ public static string Argument_CultureInvalidIdentifier
+ {
+ get { return Environment.GetResourceString("Argument_CultureInvalidIdentifier"); }
+ }
+
+ public static string Argument_CultureNotSupported
+ {
+ get { return Environment.GetResourceString("Argument_CultureNotSupported"); }
+ }
+
+ public static string Argument_CultureIsNeutral
+ {
+ get { return Environment.GetResourceString("Argument_CultureIsNeutral"); }
+ }
+
+ public static string Argument_CustomCultureCannotBePassedByNumber
+ {
+ get { return Environment.GetResourceString("Argument_CustomCultureCannotBePassedByNumber"); }
+ }
- public static string Argument_EmptyDecString
- {
- get { return Environment.GetResourceString("Argument_EmptyDecString"); }
- }
-
- public static string Argument_InvalidArrayLength
- {
- get { return Environment.GetResourceString("Argument_InvalidArrayLength"); }
- }
-
- public static string Argument_InvalidCalendar
- {
- get { return Environment.GetResourceString("Argument_InvalidCalendar"); }
- }
-
- public static string Argument_InvalidCultureName
- {
- get { return Environment.GetResourceString("Argument_InvalidCultureName"); }
- }
-
- public static string Argument_InvalidDateTimeStyles
- {
- get { return Environment.GetResourceString("Argument_InvalidDateTimeStyles"); }
- }
-
- public static string Argument_InvalidFlag
- {
- get { return Environment.GetResourceString("Argument_InvalidFlag"); }
- }
-
- public static string Argument_InvalidGroupSize
- {
- get { return Environment.GetResourceString("Argument_InvalidGroupSize"); }
- }
-
- public static string Argument_InvalidNeutralRegionName
- {
- get { return Environment.GetResourceString("Argument_InvalidNeutralRegionName"); }
- }
-
- public static string Argument_InvalidNumberStyles
- {
- get { return Environment.GetResourceString("Argument_InvalidNumberStyles"); }
- }
-
- public static string Argument_InvalidResourceCultureName
- {
- get { return Environment.GetResourceString("Argument_InvalidResourceCultureName"); }
- }
-
- public static string Argument_NoEra
- {
- get { return Environment.GetResourceString("Argument_NoEra"); }
- }
-
- public static string Argument_NoRegionInvariantCulture
- {
- get { return Environment.GetResourceString("Argument_NoRegionInvariantCulture"); }
- }
-
- public static string Argument_ResultCalendarRange
- {
- get { return Environment.GetResourceString("Argument_ResultCalendarRange"); }
- }
-
- public static string Format_BadFormatSpecifier
- {
- get { return Environment.GetResourceString("Format_BadFormatSpecifier"); }
- }
-
- public static string InvalidOperation_DateTimeParsing
- {
- get { return Environment.GetResourceString("InvalidOperation_DateTimeParsing"); }
- }
-
- public static string InvalidOperation_EnumEnded
- {
- get { return Environment.GetResourceString("InvalidOperation_EnumEnded"); }
- }
-
- public static string InvalidOperation_EnumNotStarted
- {
- get { return Environment.GetResourceString("InvalidOperation_EnumNotStarted"); }
- }
-
- public static string InvalidOperation_ReadOnly
- {
- get { return Environment.GetResourceString("InvalidOperation_ReadOnly"); }
- }
-
- public static string Overflow_TimeSpanTooLong
- {
- get { return Environment.GetResourceString("Overflow_TimeSpanTooLong"); }
- }
-
- public static string Serialization_MemberOutOfRange
- {
- get { return Environment.GetResourceString("Serialization_MemberOutOfRange"); }
- }
-
- public static string Format(string formatString, params object[] args)
- {
- return string.Format(CultureInfo.CurrentCulture, formatString, args);
- }
+ public static string Argument_EmptyDecString
+ {
+ get { return Environment.GetResourceString("Argument_EmptyDecString"); }
+ }
+
+ public static string Argument_IdnBadLabelSize
+ {
+ get { return Environment.GetResourceString("Argument_IdnBadLabelSize"); }
+ }
+
+ public static string Argument_IdnBadPunycode
+ {
+ get { return Environment.GetResourceString("Argument_IdnBadPunycode"); }
+ }
+
+ public static string Argument_IdnIllegalName
+ {
+ get { return Environment.GetResourceString("Argument_IdnIllegalName"); }
+ }
+
+ public static string Argument_InvalidArrayLength
+ {
+ get { return Environment.GetResourceString("Argument_InvalidArrayLength"); }
+ }
+
+ public static string Argument_InvalidCalendar
+ {
+ get { return Environment.GetResourceString("Argument_InvalidCalendar"); }
+ }
+
+ public static string Argument_InvalidCharSequence
+ {
+ get { return Environment.GetResourceString("Argument_InvalidCharSequence"); }
+ }
+
+ public static string Argument_InvalidCultureName
+ {
+ get { return Environment.GetResourceString("Argument_InvalidCultureName"); }
+ }
+
+ public static string Argument_InvalidDateTimeStyles
+ {
+ get { return Environment.GetResourceString("Argument_InvalidDateTimeStyles"); }
+ }
+
+ public static string Argument_InvalidDigitSubstitution
+ {
+ get { return Environment.GetResourceString("Argument_InvalidDigitSubstitution"); }
+ }
+
+ public static string Argument_InvalidFlag
+ {
+ get { return Environment.GetResourceString("Argument_InvalidFlag"); }
+ }
+
+ public static string Argument_InvalidGroupSize
+ {
+ get { return Environment.GetResourceString("Argument_InvalidGroupSize"); }
+ }
+
+ public static string Argument_InvalidNativeDigitCount
+ {
+ get { return Environment.GetResourceString("Argument_InvalidNativeDigitCount"); }
+ }
+
+ public static string Argument_InvalidNativeDigitValue
+ {
+ get { return Environment.GetResourceString("Argument_InvalidNativeDigitValue"); }
+ }
+
+ public static string Argument_InvalidNeutralRegionName
+ {
+ get { return Environment.GetResourceString("Argument_InvalidNeutralRegionName"); }
+ }
+
+ public static string Argument_InvalidNumberStyles
+ {
+ get { return Environment.GetResourceString("Argument_InvalidNumberStyles"); }
+ }
+
+ public static string Argument_InvalidResourceCultureName
+ {
+ get { return Environment.GetResourceString("Argument_InvalidResourceCultureName"); }
+ }
+
+ public static string Argument_NoEra
+ {
+ get { return Environment.GetResourceString("Argument_NoEra"); }
+ }
+
+ public static string Argument_NoRegionInvariantCulture
+ {
+ get { return Environment.GetResourceString("Argument_NoRegionInvariantCulture"); }
+ }
+
+ public static string Argument_OneOfCulturesNotSupported
+ {
+ get { return Environment.GetResourceString("Argument_OneOfCulturesNotSupported"); }
+ }
+
+ public static string Argument_OnlyMscorlib
+ {
+ get { return Environment.GetResourceString("Argument_OnlyMscorlib"); }
+ }
+
+ public static string Argument_ResultCalendarRange
+ {
+ get { return Environment.GetResourceString("Argument_ResultCalendarRange"); }
+ }
+
+ public static string Format_BadFormatSpecifier
+ {
+ get { return Environment.GetResourceString("Format_BadFormatSpecifier"); }
+ }
+
+ public static string InvalidOperation_DateTimeParsing
+ {
+ get { return Environment.GetResourceString("InvalidOperation_DateTimeParsing"); }
+ }
+
+ public static string InvalidOperation_EnumEnded
+ {
+ get { return Environment.GetResourceString("InvalidOperation_EnumEnded"); }
+ }
+
+ public static string InvalidOperation_EnumNotStarted
+ {
+ get { return Environment.GetResourceString("InvalidOperation_EnumNotStarted"); }
+ }
+
+ public static string InvalidOperation_ReadOnly
+ {
+ get { return Environment.GetResourceString("InvalidOperation_ReadOnly"); }
+ }
+
+ public static string Overflow_TimeSpanTooLong
+ {
+ get { return Environment.GetResourceString("Overflow_TimeSpanTooLong"); }
+ }
+
+ public static string Serialization_MemberOutOfRange
+ {
+ get { return Environment.GetResourceString("Serialization_MemberOutOfRange"); }
+ }
+
+ public static string Arg_InvalidHandle
+ {
+ get { return Environment.GetResourceString("Arg_InvalidHandle"); }
+ }
+
+ public static string ObjectDisposed_FileClosed
+ {
+ get { return Environment.GetResourceString("ObjectDisposed_FileClosed"); }
+ }
+
+ public static string Arg_HandleNotAsync
+ {
+ get { return Environment.GetResourceString("Arg_HandleNotAsync"); }
+ }
+
+ public static string ArgumentNull_Path
+ {
+ get { return Environment.GetResourceString("ArgumentNull_Path"); }
+ }
+
+ public static string Argument_EmptyPath
+ {
+ get { return Environment.GetResourceString("Argument_EmptyPath"); }
+ }
+
+ public static string Argument_InvalidFileModeAndAccessCombo
+ {
+ get { return Environment.GetResourceString("Argument_InvalidFileMode&AccessCombo"); }
+ }
+
+ public static string Argument_InvalidAppendMode
+ {
+ get { return Environment.GetResourceString("Argument_InvalidAppendMode"); }
+ }
+
+ public static string ArgumentNull_Buffer
+ {
+ get { return Environment.GetResourceString("ArgumentNull_Buffer"); }
+ }
+
+ public static string Argument_InvalidOffLen
+ {
+ get { return Environment.GetResourceString("Argument_InvalidOffLen"); }
+ }
+
+ public static string IO_UnknownFileName
+ {
+ get { return Environment.GetResourceString("IO_UnknownFileName"); }
+ }
+
+ public static string IO_FileStreamHandlePosition
+ {
+ get { return Environment.GetResourceString("IO.IO_FileStreamHandlePosition"); }
+ }
+
+ public static string NotSupported_FileStreamOnNonFiles
+ {
+ get { return Environment.GetResourceString("NotSupported_FileStreamOnNonFiles"); }
+ }
+
+ public static string IO_BindHandleFailed
+ {
+ get { return Environment.GetResourceString("IO.IO_BindHandleFailed"); }
+ }
+
+ public static string Arg_HandleNotSync
+ {
+ get { return Environment.GetResourceString("Arg_HandleNotSync"); }
+ }
+
+ public static string IO_SetLengthAppendTruncate
+ {
+ get { return Environment.GetResourceString("IO.IO_SetLengthAppendTruncate"); }
+ }
+
+ public static string ArgumentOutOfRange_FileLengthTooBig
+ {
+ get { return Environment.GetResourceString("ArgumentOutOfRange_FileLengthTooBig"); }
+ }
+
+ public static string Argument_InvalidSeekOrigin
+ {
+ get { return Environment.GetResourceString("Argument_InvalidSeekOrigin"); }
+ }
+
+ public static string IO_SeekAppendOverwrite
+ {
+ get { return Environment.GetResourceString("IO.IO_SeekAppendOverwrite"); }
+ }
+
+ public static string IO_FileTooLongOrHandleNotSync
+ {
+ get { return Environment.GetResourceString("IO_FileTooLongOrHandleNotSync"); }
+ }
+
+ public static string IndexOutOfRange_IORaceCondition
+ {
+ get { return Environment.GetResourceString("IndexOutOfRange_IORaceCondition"); }
+ }
+
+ public static string IO_FileNotFound
+ {
+ get { return Environment.GetResourceString("IO.FileNotFound"); }
+ }
+
+ public static string IO_FileNotFound_FileName
+ {
+ get { return Environment.GetResourceString("IO.FileNotFound_FileName"); }
+ }
+
+ public static string IO_PathNotFound_NoPathName
+ {
+ get { return Environment.GetResourceString("IO.PathNotFound_NoPathName"); }
+ }
+
+ public static string IO_PathNotFound_Path
+ {
+ get { return Environment.GetResourceString("IO.PathNotFound_Path"); }
+ }
+
+ public static string UnauthorizedAccess_IODenied_NoPathName
+ {
+ get { return Environment.GetResourceString("UnauthorizedAccess_IODenied_NoPathName"); }
+ }
+
+ public static string UnauthorizedAccess_IODenied_Path
+ {
+ get { return Environment.GetResourceString("UnauthorizedAccess_IODenied_Path"); }
+ }
+
+ public static string IO_AlreadyExists_Name
+ {
+ get { return Environment.GetResourceString("IO.IO_AlreadyExists_Name"); }
+ }
+
+ public static string IO_PathTooLong
+ {
+ get { return Environment.GetResourceString("IO.PathTooLong"); }
+ }
+
+ public static string IO_SharingViolation_NoFileName
+ {
+ get { return Environment.GetResourceString("IO.IO_SharingViolation_NoFileName"); }
+ }
+
+ public static string IO_SharingViolation_File
+ {
+ get { return Environment.GetResourceString("IO.IO_SharingViolation_File"); }
+ }
+
+ public static string IO_FileExists_Name
+ {
+ get { return Environment.GetResourceString("IO.IO_FileExists_Name"); }
+ }
+
+ public static string NotSupported_UnwritableStream
+ {
+ get { return Environment.GetResourceString("NotSupported_UnwritableStream"); }
+ }
+
+ public static string NotSupported_UnreadableStream
+ {
+ get { return Environment.GetResourceString("NotSupported_UnreadableStream"); }
+ }
+
+ public static string NotSupported_UnseekableStream
+ {
+ get { return Environment.GetResourceString("NotSupported_UnseekableStream"); }
+ }
+
+ public static string IO_EOF_ReadBeyondEOF
+ {
+ get { return Environment.GetResourceString("IO.EOF_ReadBeyondEOF"); }
+ }
+
+ public static string Argument_InvalidHandle
+ {
+ get { return Environment.GetResourceString("Argument_InvalidHandle"); }
+ }
+
+ public static string Argument_AlreadyBoundOrSyncHandle
+ {
+ get { return Environment.GetResourceString("Argument_AlreadyBoundOrSyncHandle"); }
+ }
+
+ public static string Argument_PreAllocatedAlreadyAllocated
+ {
+ get { return Environment.GetResourceString("Argument_PreAllocatedAlreadyAllocated"); }
+ }
+
+ public static string Argument_NativeOverlappedAlreadyFree
+ {
+ get { return Environment.GetResourceString("Argument_NativeOverlappedAlreadyFree"); }
+ }
+
+ public static string Argument_NativeOverlappedWrongBoundHandle
+ {
+ get { return Environment.GetResourceString("Argument_NativeOverlappedWrongBoundHandle"); }
+ }
+
+ public static string InvalidOperation_NativeOverlappedReused
+ {
+ get { return Environment.GetResourceString("InvalidOperation_NativeOverlappedReused"); }
+ }
+
+ public static string ArgumentOutOfRange_Length
+ {
+ get { return Environment.GetResourceString("ArgumentOutOfRange_Length"); }
+ }
+
+ public static string ArgumentOutOfRange_IndexString
+ {
+ get { return Environment.GetResourceString("ArgumentOutOfRange_IndexString"); }
+ }
+
+ public static string ArgumentOutOfRange_Capacity
+ {
+ get { return Environment.GetResourceString("ArgumentOutOfRange_Capacity"); }
+ }
+
+ public static string Arg_CryptographyException
+ {
+ get { return Environment.GetResourceString("Arg_CryptographyException"); }
+ }
+
+ public static string ArgumentException_BufferNotFromPool
+ {
+ get { return Environment.GetResourceString("ArgumentException_BufferNotFromPool"); }
+ }
+
+ public static string Argument_InvalidPathChars
+ {
+ get { return Environment.GetResourceString("Argument_InvalidPathChars"); }
+ }
+
+ public static string Argument_PathFormatNotSupported
+ {
+ get { return Environment.GetResourceString("Argument_PathFormatNotSupported"); }
+ }
+
+ public static string Arg_PathIllegal
+ {
+ get { return Environment.GetResourceString("Arg_PathIllegal"); }
+ }
+
+ public static string Arg_PathIllegalUNC
+ {
+ get { return Environment.GetResourceString("Arg_PathIllegalUNC"); }
+ }
+
+ public static string Arg_InvalidSearchPattern
+ {
+ get { return Environment.GetResourceString("Arg_InvalidSearchPattern"); }
+ }
+
+ public static string InvalidOperation_Cryptography
+ {
+ get { return Environment.GetResourceString("InvalidOperation_Cryptography"); }
+ }
+
+ public static string Format(string formatString, params object[] args)
+ {
+ return string.Format(CultureInfo.CurrentCulture, formatString, args);
}
}
diff --git a/src/mscorlib/corefx/System/Buffers/ArrayPool.cs b/src/mscorlib/corefx/System/Buffers/ArrayPool.cs
new file mode 100644
index 0000000000..441e48dab4
--- /dev/null
+++ b/src/mscorlib/corefx/System/Buffers/ArrayPool.cs
@@ -0,0 +1,113 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .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 type <see cref="T:T[]"/>.
+ /// </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>
+ {
+ /// <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.
+ /// </remarks>
+ public static ArrayPool<T> Shared => SharedPool.Value;
+
+ /// <summary>Stores a cached pool instance for T[].</summary>
+ /// <remarks>
+ /// Separated out into a nested class to enable lazy-initialization of the pool provided by
+ /// the runtime, only forced when Shared is used (and not when Create is called or when
+ /// other non-Shared accesses happen).
+ /// </remarks>
+ private static class SharedPool
+ {
+ /// <summary>Per-type cached pool.</summary>
+ /// <remarks>
+ /// 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.
+ /// </remarks>
+ internal readonly static ArrayPool<T> Value =
+ typeof(T) == typeof(byte) || typeof(T) == typeof(char) ? new TlsOverPerCoreLockedStacksArrayPool<T>() :
+ Create();
+ }
+
+ /// <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 <see cref="T:T[]"/> 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/src/mscorlib/corefx/System/Buffers/ArrayPoolEventSource.cs b/src/mscorlib/corefx/System/Buffers/ArrayPoolEventSource.cs
new file mode 100644
index 0000000000..9482744144
--- /dev/null
+++ b/src/mscorlib/corefx/System/Buffers/ArrayPoolEventSource.cs
@@ -0,0 +1,78 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System.Diagnostics.Tracing;
+
+namespace System.Buffers
+{
+ [EventSource(Name = "System.Buffers.ArrayPoolEventSource")]
+ internal sealed class ArrayPoolEventSource : EventSource
+ {
+ internal readonly static 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
+ }
+
+ /// <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[1].Size = sizeof(int);
+ payload[1].DataPointer = ((IntPtr)(&bufferSize));
+ payload[2].Size = sizeof(int);
+ payload[2].DataPointer = ((IntPtr)(&poolId));
+ payload[3].Size = sizeof(int);
+ payload[3].DataPointer = ((IntPtr)(&bucketId));
+ 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[1].Size = sizeof(int);
+ payload[1].DataPointer = ((IntPtr)(&bufferSize));
+ payload[2].Size = sizeof(int);
+ payload[2].DataPointer = ((IntPtr)(&poolId));
+ payload[3].Size = sizeof(int);
+ payload[3].DataPointer = ((IntPtr)(&bucketId));
+ payload[4].Size = sizeof(BufferAllocatedReason);
+ payload[4].DataPointer = ((IntPtr)(&reason));
+ 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);
+ }
+}
diff --git a/src/mscorlib/corefx/System/Buffers/ConfigurableArrayPool.cs b/src/mscorlib/corefx/System/Buffers/ConfigurableArrayPool.cs
new file mode 100644
index 0000000000..1e0e769530
--- /dev/null
+++ b/src/mscorlib/corefx/System/Buffers/ConfigurableArrayPool.cs
@@ -0,0 +1,265 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .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 EmptyArray<T>.Value;
+ }
+
+ var log = ArrayPoolEventSource.Log;
+ T[] buffer = null;
+
+ 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
+ var 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];
+
+ var 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/src/mscorlib/corefx/System/Buffers/TlsOverPerCoreLockedStacksArrayPool.Unix.cs b/src/mscorlib/corefx/System/Buffers/TlsOverPerCoreLockedStacksArrayPool.Unix.cs
new file mode 100644
index 0000000000..8a1d006b12
--- /dev/null
+++ b/src/mscorlib/corefx/System/Buffers/TlsOverPerCoreLockedStacksArrayPool.Unix.cs
@@ -0,0 +1,28 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// 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;
+using System.Runtime.CompilerServices;
+
+namespace System.Buffers
+{
+ internal sealed partial class TlsOverPerCoreLockedStacksArrayPool<T>
+ {
+ /// <summary>Get an identifier for the current thread to use to index into the stacks.</summary>
+ private static int ExecutionId
+ {
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ get
+ {
+ // On Unix, CurrentProcessorNumber is implemented in terms of sched_getcpu, which
+ // doesn't exist on all platforms. On those it doesn't exist on, GetCurrentProcessorNumber
+ // returns -1. As a fallback in that case and to spread the threads across the buckets
+ // by default, we use the current managed thread ID as a proxy.
+ int id = CurrentProcessorNumber;
+ if (id < 0) id = Environment.CurrentManagedThreadId;
+ return id;
+ }
+ }
+ }
+}
diff --git a/src/mscorlib/corefx/System/Buffers/TlsOverPerCoreLockedStacksArrayPool.Windows.cs b/src/mscorlib/corefx/System/Buffers/TlsOverPerCoreLockedStacksArrayPool.Windows.cs
new file mode 100644
index 0000000000..d42242c910
--- /dev/null
+++ b/src/mscorlib/corefx/System/Buffers/TlsOverPerCoreLockedStacksArrayPool.Windows.cs
@@ -0,0 +1,20 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// 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;
+using System.Runtime.CompilerServices;
+using System.Threading;
+
+namespace System.Buffers
+{
+ internal sealed partial class TlsOverPerCoreLockedStacksArrayPool<T> : ArrayPool<T>
+ {
+ /// <summary>Get an identifier for the current thread to use to index into the stacks.</summary>
+ private static int ExecutionId
+ {
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ get { return CurrentProcessorNumber; }
+ }
+ }
+}
diff --git a/src/mscorlib/corefx/System/Buffers/TlsOverPerCoreLockedStacksArrayPool.cs b/src/mscorlib/corefx/System/Buffers/TlsOverPerCoreLockedStacksArrayPool.cs
new file mode 100644
index 0000000000..debc33615f
--- /dev/null
+++ b/src/mscorlib/corefx/System/Buffers/TlsOverPerCoreLockedStacksArrayPool.cs
@@ -0,0 +1,328 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// 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;
+using System.Runtime.CompilerServices;
+using System.Threading;
+
+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 dumping stale buffers from the global queue, similar to PinnableBufferCache (maybe merging them).
+ // - 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;
+ /// <summary>
+ /// Cached processor number used as a hint for which per-core stack to access.
+ /// </summary>
+ [ThreadStatic]
+ private static int? t_cachedProcessorNumber;
+
+ /// <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();
+
+ /// <summary>Gets the processor number associated with the current thread.</summary>
+ /// <remarks>Uses a cached value if one exists on the current thread.</remarks>
+ private static int CurrentProcessorNumber
+ {
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ get
+ {
+ int? num = t_cachedProcessorNumber;
+ if (!num.HasValue)
+ {
+ t_cachedProcessorNumber = num = Environment.CurrentProcessorNumber;
+ }
+ return num.GetValueOrDefault();
+ }
+ }
+
+ 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 EmptyArray<T>.Value;
+ }
+
+ 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 = new 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 = 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, 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;
+ }
+ else
+ {
+ T[] prev = tlsBuckets[bucketIndex];
+ tlsBuckets[bucketIndex] = array;
+ if (prev != null)
+ {
+ PerCoreLockedStacks bucket = _buckets[bucketIndex] ?? CreatePerCoreLockedStacks(bucketIndex);
+ bucket.TryPush(prev);
+ }
+ }
+ }
+
+ // Log that the buffer was returned
+ ArrayPoolEventSource log = ArrayPoolEventSource.Log;
+ if (log.IsEnabled())
+ {
+ log.BufferReturned(array.GetHashCode(), array.Length, Id);
+ }
+ }
+
+ /// <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 = ExecutionId % 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 = ExecutionId % 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;
+ }
+ }
+
+ /// <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;
+
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public bool TryPush(T[] array)
+ {
+ bool enqueued = false;
+ MonitorEnterWithProcNumberFlush(this);
+ if (_count < MaxBuffersPerArraySizePerCore)
+ {
+ _arrays[_count++] = array;
+ enqueued = true;
+ }
+ Monitor.Exit(this);
+ return enqueued;
+ }
+
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public T[] TryPop()
+ {
+ T[] arr = null;
+ MonitorEnterWithProcNumberFlush(this);
+ if (_count > 0)
+ {
+ arr = _arrays[--_count];
+ _arrays[_count] = null;
+ }
+ Monitor.Exit(this);
+ return arr;
+ }
+
+ /// <summary>
+ /// Enters the monitor on the object. If there is any contention while trying
+ /// to acquire the monitor, it flushes the cached processor number so that subsequent
+ /// attempts to access the per-core stacks will use an updated processor number.
+ /// </summary>
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ private static void MonitorEnterWithProcNumberFlush(object obj)
+ {
+ if (!Monitor.TryEnter(obj))
+ {
+ t_cachedProcessorNumber = null;
+ Monitor.Enter(obj);
+ }
+ }
+ }
+ }
+}
diff --git a/src/mscorlib/corefx/System/Buffers/Utilities.cs b/src/mscorlib/corefx/System/Buffers/Utilities.cs
new file mode 100644
index 0000000000..823299f5fc
--- /dev/null
+++ b/src/mscorlib/corefx/System/Buffers/Utilities.cs
@@ -0,0 +1,35 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .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
+{
+ internal static class Utilities
+ {
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ internal static int SelectBucketIndex(int bufferSize)
+ {
+ uint bitsRemaining = ((uint)bufferSize - 1) >> 4;
+
+ int poolIndex = 0;
+ if (bitsRemaining > 0xFFFF) { bitsRemaining >>= 16; poolIndex = 16; }
+ if (bitsRemaining > 0xFF) { bitsRemaining >>= 8; poolIndex += 8; }
+ if (bitsRemaining > 0xF) { bitsRemaining >>= 4; poolIndex += 4; }
+ if (bitsRemaining > 0x3) { bitsRemaining >>= 2; poolIndex += 2; }
+ if (bitsRemaining > 0x1) { bitsRemaining >>= 1; poolIndex += 1; }
+
+ return poolIndex + (int)bitsRemaining;
+ }
+
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ internal static int GetMaxSizeForBucket(int binIndex)
+ {
+ int maxSize = 16 << binIndex;
+ Debug.Assert(maxSize >= 0);
+ return maxSize;
+ }
+ }
+}
diff --git a/src/mscorlib/corefx/System/Globalization/Calendar.cs b/src/mscorlib/corefx/System/Globalization/Calendar.cs
index 343682d156..78e9f00d08 100644
--- a/src/mscorlib/corefx/System/Globalization/Calendar.cs
+++ b/src/mscorlib/corefx/System/Globalization/Calendar.cs
@@ -2,9 +2,7 @@
// The .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.Globalization;
+using System.Diagnostics;
using System.Diagnostics.Contracts;
using System.Runtime.Serialization;
@@ -99,8 +97,14 @@ namespace System.Globalization
}
}
-
-
+ [System.Runtime.InteropServices.ComVisible(false)]
+ public virtual CalendarAlgorithmType AlgorithmType
+ {
+ get
+ {
+ return CalendarAlgorithmType.Unknown;
+ }
+ }
protected Calendar()
{
@@ -164,9 +168,9 @@ namespace System.Globalization
//
////////////////////////////////////////////////////////////////////////
[System.Runtime.InteropServices.ComVisible(false)]
- internal static Calendar ReadOnly(Calendar calendar)
+ public static Calendar ReadOnly(Calendar calendar)
{
- if (calendar == null) { throw new ArgumentNullException("calendar"); }
+ if (calendar == null) { throw new ArgumentNullException(nameof(calendar)); }
Contract.EndContractBlock();
if (calendar.IsReadOnly) { return (calendar); }
@@ -206,7 +210,7 @@ namespace System.Globalization
// The following code assumes that the current era value can not be -1.
if (_currentEraValue == -1)
{
- Contract.Assert(BaseCalendarID != CalendarId.UNINITIALIZED_VALUE, "[Calendar.CurrentEraValue] Expected a real calendar ID");
+ Debug.Assert(BaseCalendarID != CalendarId.UNINITIALIZED_VALUE, "[Calendar.CurrentEraValue] Expected a real calendar ID");
_currentEraValue = CalendarData.GetCalendarData(BaseCalendarID).iCurrentEra;
}
return (_currentEraValue);
@@ -242,7 +246,7 @@ namespace System.Globalization
double tempMillis = (value * scale + (value >= 0 ? 0.5 : -0.5));
if (!((tempMillis > -(double)MaxMillis) && (tempMillis < (double)MaxMillis)))
{
- throw new ArgumentOutOfRangeException("value", SR.ArgumentOutOfRange_AddValue);
+ throw new ArgumentOutOfRangeException(nameof(value), SR.ArgumentOutOfRange_AddValue);
}
long millis = (long)tempMillis;
@@ -521,7 +525,7 @@ namespace System.Globalization
// 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;
- Contract.Assert(offset >= 0, "Calendar.GetFirstDayWeekOfYear(): offset >= 0");
+ Debug.Assert(offset >= 0, "Calendar.GetFirstDayWeekOfYear(): offset >= 0");
return ((dayOfYear + offset) / 7 + 1);
}
@@ -646,7 +650,7 @@ namespace System.Globalization
if ((int)firstDayOfWeek < 0 || (int)firstDayOfWeek > 6)
{
throw new ArgumentOutOfRangeException(
- "firstDayOfWeek", SR.Format(SR.ArgumentOutOfRange_Range,
+ nameof(firstDayOfWeek), SR.Format(SR.ArgumentOutOfRange_Range,
DayOfWeek.Sunday, DayOfWeek.Saturday));
}
Contract.EndContractBlock();
@@ -660,7 +664,7 @@ namespace System.Globalization
return (GetWeekOfYearFullDays(time, (int)firstDayOfWeek, 4));
}
throw new ArgumentOutOfRangeException(
- "rule", SR.Format(SR.ArgumentOutOfRange_Range,
+ nameof(rule), SR.Format(SR.ArgumentOutOfRange_Range,
CalendarWeekRule.FirstDay, CalendarWeekRule.FirstFourDayWeek));
}
@@ -700,6 +704,16 @@ namespace System.Globalization
public abstract bool IsLeapMonth(int year, int month, int era);
+ // 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.
+ //
+
+ [System.Runtime.InteropServices.ComVisible(false)]
+ public virtual int GetLeapMonth(int year)
+ {
+ return (GetLeapMonth(year, CurrentEra));
+ }
+
// 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.
//
@@ -808,7 +822,7 @@ namespace System.Globalization
{
if (year < 0)
{
- throw new ArgumentOutOfRangeException("year",
+ throw new ArgumentOutOfRangeException(nameof(year),
SR.ArgumentOutOfRange_NeedNonNegNum);
}
Contract.EndContractBlock();
@@ -830,7 +844,7 @@ namespace System.Globalization
if (millisecond < 0 || millisecond >= MillisPerSecond)
{
throw new ArgumentOutOfRangeException(
- "millisecond",
+ nameof(millisecond),
String.Format(
CultureInfo.InvariantCulture,
SR.Format(SR.ArgumentOutOfRange_Range, 0, MillisPerSecond - 1)));
diff --git a/src/mscorlib/corefx/System/Globalization/CalendarAlgorithmType.cs b/src/mscorlib/corefx/System/Globalization/CalendarAlgorithmType.cs
new file mode 100644
index 0000000000..159b0e6f77
--- /dev/null
+++ b/src/mscorlib/corefx/System/Globalization/CalendarAlgorithmType.cs
@@ -0,0 +1,20 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .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 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/src/mscorlib/corefx/System/Globalization/CalendarData.Unix.cs b/src/mscorlib/corefx/System/Globalization/CalendarData.Unix.cs
index 6c6a18ec37..270d62f143 100644
--- a/src/mscorlib/corefx/System/Globalization/CalendarData.Unix.cs
+++ b/src/mscorlib/corefx/System/Globalization/CalendarData.Unix.cs
@@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.
using System.Collections.Generic;
+using System.Diagnostics;
using System.Diagnostics.Contracts;
using System.Runtime.InteropServices;
using System.Security;
@@ -200,7 +201,7 @@ namespace System.Globalization
break;
default:
const string unsupportedDateFieldSymbols = "YuUrQqwWDFg";
- Contract.Assert(unsupportedDateFieldSymbols.IndexOf(input[index]) == -1,
+ Debug.Assert(unsupportedDateFieldSymbols.IndexOf(input[index]) == -1,
string.Format(CultureInfo.InvariantCulture,
"Encountered an unexpected date field symbol '{0}' from ICU which has no known corresponding .NET equivalent.",
input[index]));
diff --git a/src/mscorlib/corefx/System/Globalization/CalendarData.cs b/src/mscorlib/corefx/System/Globalization/CalendarData.cs
index 2dbd1b8069..d22bd67ac1 100644
--- a/src/mscorlib/corefx/System/Globalization/CalendarData.cs
+++ b/src/mscorlib/corefx/System/Globalization/CalendarData.cs
@@ -2,11 +2,7 @@
// The .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;
-using System.Diagnostics.Contracts;
-using System.Collections.Generic;
+using System.Diagnostics;
namespace System.Globalization
{
@@ -108,7 +104,7 @@ namespace System.Globalization
if (!LoadCalendarDataFromSystem(localeName, calendarId))
{
- Contract.Assert(false, "[CalendarData] LoadCalendarDataFromSystem call isn't expected to fail for calendar " + calendarId + " locale " + localeName);
+ Debug.Assert(false, "[CalendarData] LoadCalendarDataFromSystem call isn't expected to fail for calendar " + calendarId + " locale " + localeName);
// Something failed, try invariant for missing parts
// This is really not good, but we don't want the callers to crash.
diff --git a/src/mscorlib/corefx/System/Globalization/CalendricalCalculationsHelper.cs b/src/mscorlib/corefx/System/Globalization/CalendricalCalculationsHelper.cs
index ba7601b420..149e63c689 100644
--- a/src/mscorlib/corefx/System/Globalization/CalendricalCalculationsHelper.cs
+++ b/src/mscorlib/corefx/System/Globalization/CalendricalCalculationsHelper.cs
@@ -2,8 +2,7 @@
// The .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.Contracts;
+using System.Diagnostics;
namespace System.Globalization
{
@@ -126,7 +125,7 @@ namespace System.Globalization
return longitude;
}
- static public double AsDayFraction(double longitude)
+ public static double AsDayFraction(double longitude)
{
return longitude / FullCircleOfArc;
}
@@ -153,7 +152,7 @@ namespace System.Globalization
// 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)
{
- Contract.Assert(gregorianYear < 1620 || 2020 <= gregorianYear);
+ Debug.Assert(gregorianYear < 1620 || 2020 <= gregorianYear);
long january1stOfYear = GetNumberOfDays(new DateTime(gregorianYear, 1, 1));
double daysSinceStartOf1810 = january1stOfYear - StartOf1810;
double x = TwelveHours + daysSinceStartOf1810;
@@ -162,34 +161,34 @@ namespace System.Globalization
private static double EphemerisCorrection1988to2019(int gregorianYear)
{
- Contract.Assert(1988 <= gregorianYear && gregorianYear <= 2019);
+ Debug.Assert(1988 <= gregorianYear && gregorianYear <= 2019);
return (double)(gregorianYear - 1933) / SecondsPerDay;
}
private static double EphemerisCorrection1900to1987(int gregorianYear)
{
- Contract.Assert(1900 <= gregorianYear && gregorianYear <= 1987);
+ Debug.Assert(1900 <= gregorianYear && gregorianYear <= 1987);
double centuriesFrom1900 = CenturiesFrom1900(gregorianYear);
return PolynomialSum(s_coefficients1900to1987, centuriesFrom1900);
}
private static double EphemerisCorrection1800to1899(int gregorianYear)
{
- Contract.Assert(1800 <= gregorianYear && gregorianYear <= 1899);
+ Debug.Assert(1800 <= gregorianYear && gregorianYear <= 1899);
double centuriesFrom1900 = CenturiesFrom1900(gregorianYear);
return PolynomialSum(s_coefficients1800to1899, centuriesFrom1900);
}
private static double EphemerisCorrection1700to1799(int gregorianYear)
{
- Contract.Assert(1700 <= gregorianYear && gregorianYear <= 1799);
+ Debug.Assert(1700 <= gregorianYear && gregorianYear <= 1799);
double yearsSince1700 = gregorianYear - 1700;
return PolynomialSum(s_coefficients1700to1799, yearsSince1700) / SecondsPerDay;
}
private static double EphemerisCorrection1620to1699(int gregorianYear)
{
- Contract.Assert(1620 <= gregorianYear && gregorianYear <= 1699);
+ Debug.Assert(1620 <= gregorianYear && gregorianYear <= 1699);
double yearsSince1600 = gregorianYear - 1600;
return PolynomialSum(s_coefficients1620to1699, yearsSince1600) / SecondsPerDay;
}
@@ -216,11 +215,11 @@ namespace System.Globalization
}
}
- Contract.Assert(false, "Not expected to come here");
+ Debug.Assert(false, "Not expected to come here");
return DefaultEphemerisCorrection(year);
}
- static public double JulianCenturies(double moment)
+ public static double JulianCenturies(double moment)
{
double dynamicalMoment = moment + EphemerisCorrection(moment);
return (dynamicalMoment - Noon2000Jan01) / DaysInUniformLengthCentury;
@@ -274,7 +273,7 @@ namespace System.Globalization
}
// midday
- static public double Midday(double date, double longitude)
+ public static double Midday(double date, double longitude)
{
return AsLocalTime(date + TwelveHours, longitude) - AsDayFraction(longitude);
}
@@ -285,7 +284,7 @@ namespace System.Globalization
}
// midday-in-tehran
- static public double MiddayAtPersianObservationSite(double date)
+ 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
}
@@ -362,7 +361,7 @@ namespace System.Globalization
return (-0.004778 * SinOfDegree(a)) - (0.0003667 * SinOfDegree(b));
}
- static public double Compute(double time)
+ public static double Compute(double time)
{
double julianCenturies = JulianCenturies(time);
double lambda = 282.7771834
@@ -373,7 +372,7 @@ namespace System.Globalization
return InitLongitude(longitude);
}
- static public double AsSeason(double longitude)
+ public static double AsSeason(double longitude)
{
return (longitude < 0) ? (longitude + FullCircleOfArc) : longitude;
}
@@ -405,7 +404,7 @@ namespace System.Globalization
break;
}
}
- Contract.Assert(day != upperBoundNewYearDay);
+ Debug.Assert(day != upperBoundNewYearDay);
return day - 1;
}
diff --git a/src/mscorlib/corefx/System/Globalization/CharUnicodeInfo.cs b/src/mscorlib/corefx/System/Globalization/CharUnicodeInfo.cs
index 4cb95fb8f1..dc38ca405b 100644
--- a/src/mscorlib/corefx/System/Globalization/CharUnicodeInfo.cs
+++ b/src/mscorlib/corefx/System/Globalization/CharUnicodeInfo.cs
@@ -12,12 +12,7 @@
//
////////////////////////////////////////////////////////////////////////////
-using System;
-using System.Threading;
-using System.Runtime.InteropServices;
-using System.Runtime.CompilerServices;
-using System.Reflection;
-using System.Security;
+using System.Diagnostics;
using System.Diagnostics.Contracts;
namespace System.Globalization
@@ -59,8 +54,8 @@ namespace System.Globalization
internal static int InternalConvertToUtf32(String s, int index)
{
- Contract.Assert(s != null, "s != null");
- Contract.Assert(index >= 0 && index < s.Length, "index < s.Length");
+ 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;
@@ -100,9 +95,9 @@ namespace System.Globalization
internal static int InternalConvertToUtf32(String s, int index, out int charLength)
{
- Contract.Assert(s != null, "s != null");
- Contract.Assert(s.Length > 0, "s.Length > 0");
- Contract.Assert(index >= 0 && index < s.Length, "index >= 0 && index < s.Length");
+ 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)
{
@@ -131,8 +126,8 @@ namespace System.Globalization
internal static bool IsWhiteSpace(String s, int index)
{
- Contract.Assert(s != null, "s!=null");
- Contract.Assert(index >= 0 && index < s.Length, "index >= 0 && index < s.Length");
+ Debug.Assert(s != null, "s!=null");
+ Debug.Assert(index >= 0 && index < s.Length, "index >= 0 && index < s.Length");
UnicodeCategory uc = GetUnicodeCategory(s, index);
// In Unicode 3.0, U+2028 is the only character which is under the category "LineSeparator".
@@ -170,9 +165,9 @@ namespace System.Globalization
//
// Note that for ch in the range D800-DFFF we just treat it as any other non-numeric character
//
- internal unsafe static double InternalGetNumericValue(int ch)
+ internal static unsafe double InternalGetNumericValue(int ch)
{
- Contract.Assert(ch >= 0 && ch <= 0x10ffff, "ch is not in valid Unicode range.");
+ 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.
ushort index = s_pNumericLevel1Index[ch >> 8];
// Get the level 2 WORD offset from the 4 - 7 bit of ch. This provides the base offset of the level 3 table.
@@ -191,6 +186,21 @@ namespace System.Globalization
}
}
+ internal static unsafe ushort InternalGetDigitValues(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.
+ ushort index = s_pNumericLevel1Index[ch >> 8];
+ // Get the level 2 WORD 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 = s_pNumericLevel1Index[index + ((ch >> 4) & 0x000f)];
+
+ fixed (ushort* pUshortPtr = &(s_pNumericLevel1Index[index]))
+ {
+ byte* pBytePtr = (byte*)pUshortPtr;
+ return s_pDigitValues[pBytePtr[(ch & 0x000f)]];
+ }
+ }
////////////////////////////////////////////////////////////////////////
//
@@ -218,16 +228,58 @@ namespace System.Globalization
{
if (s == null)
{
- throw new ArgumentNullException("s");
+ throw new ArgumentNullException(nameof(s));
}
if (index < 0 || index >= s.Length)
{
- throw new ArgumentOutOfRangeException("index", SR.ArgumentOutOfRange_Index);
+ throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index);
}
Contract.EndContractBlock();
return (InternalGetNumericValue(InternalConvertToUtf32(s, index)));
}
+ public static int GetDecimalDigitValue(char ch)
+ {
+ return (sbyte) (InternalGetDigitValues(ch) >> 8);
+ }
+
+ 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);
+ }
+ Contract.EndContractBlock();
+
+ return (sbyte) (InternalGetDigitValues(InternalConvertToUtf32(s, index)) >> 8);
+ }
+
+ public static int GetDigitValue(char ch)
+ {
+ return (sbyte) (InternalGetDigitValues(ch) & 0x00FF);
+ }
+
+ 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);
+ }
+
+ Contract.EndContractBlock();
+ return (sbyte) (InternalGetDigitValues(InternalConvertToUtf32(s, index)) & 0x00FF);
+ }
+
public static UnicodeCategory GetUnicodeCategory(char ch)
{
return (InternalGetUnicodeCategory(ch));
@@ -236,16 +288,16 @@ namespace System.Globalization
public static UnicodeCategory GetUnicodeCategory(String s, int index)
{
if (s == null)
- throw new ArgumentNullException("s");
+ throw new ArgumentNullException(nameof(s));
if (((uint)index) >= ((uint)s.Length))
{
- throw new ArgumentOutOfRangeException("index");
+ throw new ArgumentOutOfRangeException(nameof(index));
}
Contract.EndContractBlock();
return InternalGetUnicodeCategory(s, index);
}
- internal unsafe static UnicodeCategory InternalGetUnicodeCategory(int ch)
+ internal static unsafe UnicodeCategory InternalGetUnicodeCategory(int ch)
{
return ((UnicodeCategory)InternalGetCategoryValue(ch, UNICODE_CATEGORY_OFFSET));
}
@@ -265,9 +317,9 @@ namespace System.Globalization
//
////////////////////////////////////////////////////////////////////////
- internal unsafe static byte InternalGetCategoryValue(int ch, int offset)
+ internal static unsafe byte InternalGetCategoryValue(int ch, int offset)
{
- Contract.Assert(ch >= 0 && ch <= 0x10ffff, "ch is not in valid Unicode range.");
+ 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.
ushort index = s_pCategoryLevel1Index[ch >> 8];
// Get the level 2 WORD offset from the 4 - 7 bit of ch. This provides the base offset of the level 3 table.
@@ -284,7 +336,7 @@ namespace System.Globalization
// Make sure that OtherNotAssigned is the last category in UnicodeCategory.
// If that changes, change the following assertion as well.
//
- //Contract.Assert(uc >= 0 && uc <= UnicodeCategory.OtherNotAssigned, "Table returns incorrect Unicode category");
+ //Debug.Assert(uc >= 0 && uc <= UnicodeCategory.OtherNotAssigned, "Table returns incorrect Unicode category");
return (uc);
}
}
@@ -304,8 +356,8 @@ namespace System.Globalization
internal static UnicodeCategory InternalGetUnicodeCategory(String value, int index)
{
- Contract.Assert(value != null, "value can not be null");
- Contract.Assert(index < value.Length, "index < value.Length");
+ Debug.Assert(value != null, "value can not be null");
+ Debug.Assert(index < value.Length, "index < value.Length");
return (InternalGetUnicodeCategory(InternalConvertToUtf32(value, index)));
}
@@ -319,16 +371,16 @@ namespace System.Globalization
internal static UnicodeCategory InternalGetUnicodeCategory(String str, int index, out int charLength)
{
- Contract.Assert(str != null, "str can not be null");
- Contract.Assert(str.Length > 0, "str.Length > 0"); ;
- Contract.Assert(index >= 0 && index < str.Length, "index >= 0 && index < str.Length");
+ 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 (InternalGetUnicodeCategory(InternalConvertToUtf32(str, index, out charLength)));
}
internal static bool IsCombiningCategory(UnicodeCategory uc)
{
- Contract.Assert(uc >= 0, "uc >= 0");
+ Debug.Assert(uc >= 0, "uc >= 0");
return (
uc == UnicodeCategory.NonSpacingMark ||
uc == UnicodeCategory.SpacingCombiningMark ||
diff --git a/src/mscorlib/corefx/System/Globalization/CharUnicodeInfoData.cs b/src/mscorlib/corefx/System/Globalization/CharUnicodeInfoData.cs
index 7284cfd3bc..b1bef8146e 100644
--- a/src/mscorlib/corefx/System/Globalization/CharUnicodeInfoData.cs
+++ b/src/mscorlib/corefx/System/Globalization/CharUnicodeInfoData.cs
@@ -1218,5 +1218,30 @@ namespace System.Globalization
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
};
+
+ private static ushort[] s_pDigitValues = new ushort []
+ {
+ 0xffff, 0x0000, 0x0101, 0x0202, 0x0303, 0x0404, 0x0505, 0x0606,
+ 0x0707, 0x0808, 0x0909, 0xff02, 0xff03, 0xff01, 0xffff, 0xffff,
+ 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
+ 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
+ 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xff04, 0xff05, 0xff06,
+ 0xff07, 0xff08, 0xff09, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
+ 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
+ 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xff00, 0xffff, 0xffff,
+ 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
+ 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
+ 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
+ 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
+ 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
+ 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
+ 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
+ 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
+ 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
+ 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
+ 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
+ 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x0000, 0x0000
+ };
+
}
}
diff --git a/src/mscorlib/corefx/System/Globalization/ChineseLunisolarCalendar.cs b/src/mscorlib/corefx/System/Globalization/ChineseLunisolarCalendar.cs
index 48f62019d7..271d9802ce 100644
--- a/src/mscorlib/corefx/System/Globalization/ChineseLunisolarCalendar.cs
+++ b/src/mscorlib/corefx/System/Globalization/ChineseLunisolarCalendar.cs
@@ -342,13 +342,13 @@ namespace System.Globalization
{
if (era != CurrentEra && era != ChineseEra)
{
- throw new ArgumentOutOfRangeException("era", SR.ArgumentOutOfRange_InvalidEraValue);
+ throw new ArgumentOutOfRangeException(nameof(era), SR.ArgumentOutOfRange_InvalidEraValue);
}
if (year < MIN_LUNISOLAR_YEAR || year > MAX_LUNISOLAR_YEAR)
{
throw new ArgumentOutOfRangeException(
- "year",
+ nameof(year),
String.Format(
CultureInfo.CurrentCulture,
SR.ArgumentOutOfRange_Range, MIN_LUNISOLAR_YEAR, MAX_LUNISOLAR_YEAR));
diff --git a/src/mscorlib/corefx/System/Globalization/CompareInfo.Unix.cs b/src/mscorlib/corefx/System/Globalization/CompareInfo.Unix.cs
index 2aaf5a22fa..21c3c9f7e4 100644
--- a/src/mscorlib/corefx/System/Globalization/CompareInfo.Unix.cs
+++ b/src/mscorlib/corefx/System/Globalization/CompareInfo.Unix.cs
@@ -2,6 +2,7 @@
// The .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.Contracts;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@@ -17,7 +18,6 @@ namespace System.Globalization
[NonSerialized]
private bool _isAsciiEqualityOrdinal;
- [SecuritySafeCritical]
internal CompareInfo(CultureInfo culture)
{
_name = culture.m_name;
@@ -27,14 +27,23 @@ namespace System.Globalization
private void InitSort(CultureInfo culture)
{
_sortName = culture.SortName;
- _sortHandle = Interop.GlobalizationInterop.GetSortHandle(GetNullTerminatedUtf8String(_sortName));
+ Interop.GlobalizationInterop.ResultCode resultCode = Interop.GlobalizationInterop.GetSortHandle(GetNullTerminatedUtf8String(_sortName), out _sortHandle);
+ if (resultCode != Interop.GlobalizationInterop.ResultCode.Success)
+ {
+ _sortHandle.Dispose();
+
+ if (resultCode == Interop.GlobalizationInterop.ResultCode.OutOfMemory)
+ throw new OutOfMemoryException();
+
+ throw new ExternalException(SR.Arg_ExternalException);
+ }
_isAsciiEqualityOrdinal = (_sortName == "en-US" || _sortName == "");
}
internal static unsafe int IndexOfOrdinal(string source, string value, int startIndex, int count, bool ignoreCase)
{
- Contract.Assert(source != null);
- Contract.Assert(value != null);
+ Debug.Assert(source != null);
+ Debug.Assert(value != null);
if (value.Length == 0)
{
@@ -77,8 +86,8 @@ namespace System.Globalization
internal static unsafe int LastIndexOfOrdinal(string source, string value, int startIndex, int count, bool ignoreCase)
{
- Contract.Assert(source != null);
- Contract.Assert(value != null);
+ Debug.Assert(source != null);
+ Debug.Assert(value != null);
if (value.Length == 0)
{
@@ -124,8 +133,8 @@ namespace System.Globalization
private int GetHashCodeOfStringCore(string source, CompareOptions options)
{
- Contract.Assert(source != null);
- Contract.Assert((options & (CompareOptions.Ordinal | CompareOptions.OrdinalIgnoreCase)) == 0);
+ Debug.Assert(source != null);
+ Debug.Assert((options & (CompareOptions.Ordinal | CompareOptions.OrdinalIgnoreCase)) == 0);
return GetHashCodeOfStringCore(source, options, forceRandomizedHashing: false, additionalEntropy: 0);
}
@@ -137,9 +146,9 @@ namespace System.Globalization
private unsafe int CompareString(string string1, int offset1, int length1, string string2, int offset2, int length2, CompareOptions options)
{
- Contract.Assert(string1 != null);
- Contract.Assert(string2 != null);
- Contract.Assert((options & (CompareOptions.Ordinal | CompareOptions.OrdinalIgnoreCase)) == 0);
+ Debug.Assert(string1 != null);
+ Debug.Assert(string2 != null);
+ Debug.Assert((options & (CompareOptions.Ordinal | CompareOptions.OrdinalIgnoreCase)) == 0);
fixed (char* pString1 = string1)
{
@@ -152,9 +161,9 @@ namespace System.Globalization
private unsafe int IndexOfCore(string source, string target, int startIndex, int count, CompareOptions options)
{
- Contract.Assert(!string.IsNullOrEmpty(source));
- Contract.Assert(target != null);
- Contract.Assert((options & CompareOptions.OrdinalIgnoreCase) == 0);
+ Debug.Assert(!string.IsNullOrEmpty(source));
+ Debug.Assert(target != null);
+ Debug.Assert((options & CompareOptions.OrdinalIgnoreCase) == 0);
if (target.Length == 0)
{
@@ -181,9 +190,9 @@ namespace System.Globalization
private unsafe int LastIndexOfCore(string source, string target, int startIndex, int count, CompareOptions options)
{
- Contract.Assert(!string.IsNullOrEmpty(source));
- Contract.Assert(target != null);
- Contract.Assert((options & CompareOptions.OrdinalIgnoreCase) == 0);
+ Debug.Assert(!string.IsNullOrEmpty(source));
+ Debug.Assert(target != null);
+ Debug.Assert((options & CompareOptions.OrdinalIgnoreCase) == 0);
if (target.Length == 0)
{
@@ -212,12 +221,11 @@ namespace System.Globalization
}
}
- [SecuritySafeCritical]
private bool StartsWith(string source, string prefix, CompareOptions options)
{
- Contract.Assert(!string.IsNullOrEmpty(source));
- Contract.Assert(!string.IsNullOrEmpty(prefix));
- Contract.Assert((options & (CompareOptions.Ordinal | CompareOptions.OrdinalIgnoreCase)) == 0);
+ Debug.Assert(!string.IsNullOrEmpty(source));
+ Debug.Assert(!string.IsNullOrEmpty(prefix));
+ Debug.Assert((options & (CompareOptions.Ordinal | CompareOptions.OrdinalIgnoreCase)) == 0);
if (_isAsciiEqualityOrdinal && CanUseAsciiOrdinalForOptions(options) && source.IsFastSort() && prefix.IsFastSort())
{
@@ -227,12 +235,11 @@ namespace System.Globalization
return Interop.GlobalizationInterop.StartsWith(_sortHandle, prefix, prefix.Length, source, source.Length, options);
}
- [SecuritySafeCritical]
private bool EndsWith(string source, string suffix, CompareOptions options)
{
- Contract.Assert(!string.IsNullOrEmpty(source));
- Contract.Assert(!string.IsNullOrEmpty(suffix));
- Contract.Assert((options & (CompareOptions.Ordinal | CompareOptions.OrdinalIgnoreCase)) == 0);
+ Debug.Assert(!string.IsNullOrEmpty(source));
+ Debug.Assert(!string.IsNullOrEmpty(suffix));
+ Debug.Assert((options & (CompareOptions.Ordinal | CompareOptions.OrdinalIgnoreCase)) == 0);
if (_isAsciiEqualityOrdinal && CanUseAsciiOrdinalForOptions(options) && source.IsFastSort() && suffix.IsFastSort())
{
@@ -241,16 +248,81 @@ namespace System.Globalization
return Interop.GlobalizationInterop.EndsWith(_sortHandle, suffix, suffix.Length, source, source.Length, options);
}
+
+ private unsafe SortKey CreateSortKey(String source, CompareOptions options)
+ {
+ if (source==null) { throw new ArgumentNullException(nameof(source)); }
+ Contract.EndContractBlock();
+
+ if ((options & ValidSortkeyCtorMaskOffFlags) != 0)
+ {
+ throw new ArgumentException(Environment.GetResourceString("Argument_InvalidFlag"), nameof(options));
+ }
+
+ byte [] keyData;
+ if (source.Length == 0)
+ {
+ keyData = EmptyArray<Byte>.Value;
+ }
+ else
+ {
+ int sortKeyLength = Interop.GlobalizationInterop.GetSortKey(_sortHandle, source, source.Length, null, 0, options);
+ keyData = new byte[sortKeyLength];
+
+ fixed (byte* pSortKey = keyData)
+ {
+ Interop.GlobalizationInterop.GetSortKey(_sortHandle, source, source.Length, pSortKey, sortKeyLength, options);
+ }
+ }
+
+ return new SortKey(Name, source, options, keyData);
+ }
+
+ private unsafe static bool IsSortable(char *text, int length)
+ {
+ 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.InternalGetUnicodeCategory(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 ----
// -----------------------------
- [SecuritySafeCritical]
internal unsafe int GetHashCodeOfStringCore(string source, CompareOptions options, bool forceRandomizedHashing, long additionalEntropy)
{
- Contract.Assert(source != null);
- Contract.Assert((options & (CompareOptions.Ordinal | CompareOptions.OrdinalIgnoreCase)) == 0);
+ Debug.Assert(source != null);
+ Debug.Assert((options & (CompareOptions.Ordinal | CompareOptions.OrdinalIgnoreCase)) == 0);
if (source.Length == 0)
{
@@ -307,9 +379,19 @@ namespace System.Globalization
int bytesWritten = System.Text.Encoding.UTF8.GetBytes(s, 0, s.Length, buffer, 0);
- Contract.Assert(bytesWritten == byteLen);
+ Debug.Assert(bytesWritten == byteLen);
return buffer;
}
+
+ private SortVersion GetSortVersion()
+ {
+ int sortVersion = Interop.GlobalizationInterop.GetSortVersion();
+ 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)));
+ }
}
}
diff --git a/src/mscorlib/corefx/System/Globalization/CompareInfo.Windows.cs b/src/mscorlib/corefx/System/Globalization/CompareInfo.Windows.cs
index 744a48b107..4ebaf9cb10 100644
--- a/src/mscorlib/corefx/System/Globalization/CompareInfo.Windows.cs
+++ b/src/mscorlib/corefx/System/Globalization/CompareInfo.Windows.cs
@@ -2,6 +2,7 @@
// The .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.Contracts;
namespace System.Globalization
@@ -53,24 +54,24 @@ namespace System.Globalization
internal static int IndexOfOrdinal(string source, string value, int startIndex, int count, bool ignoreCase)
{
- Contract.Assert(source != null);
- Contract.Assert(value != null);
+ Debug.Assert(source != null);
+ Debug.Assert(value != null);
return FindStringOrdinal(FIND_FROMSTART, source, startIndex, count, value, value.Length, ignoreCase);
}
internal static int LastIndexOfOrdinal(string source, string value, int startIndex, int count, bool ignoreCase)
{
- Contract.Assert(source != null);
- Contract.Assert(value != null);
+ 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(string source, CompareOptions options)
{
- Contract.Assert(source != null);
- Contract.Assert((options & (CompareOptions.Ordinal | CompareOptions.OrdinalIgnoreCase)) == 0);
+ Debug.Assert(source != null);
+ Debug.Assert((options & (CompareOptions.Ordinal | CompareOptions.OrdinalIgnoreCase)) == 0);
if (source.Length == 0)
{
@@ -102,9 +103,9 @@ namespace System.Globalization
private unsafe int CompareString(string string1, int offset1, int length1, string string2, int offset2, int length2, CompareOptions options)
{
- Contract.Assert(string1 != null);
- Contract.Assert(string2 != null);
- Contract.Assert((options & (CompareOptions.Ordinal | CompareOptions.OrdinalIgnoreCase)) == 0);
+ Debug.Assert(string1 != null);
+ Debug.Assert(string2 != null);
+ Debug.Assert((options & (CompareOptions.Ordinal | CompareOptions.OrdinalIgnoreCase)) == 0);
string localeName = _sortHandle != IntPtr.Zero ? null : _sortName;
@@ -167,9 +168,9 @@ namespace System.Globalization
private int IndexOfCore(string source, string target, int startIndex, int count, CompareOptions options)
{
- Contract.Assert(!string.IsNullOrEmpty(source));
- Contract.Assert(target != null);
- Contract.Assert((options & CompareOptions.OrdinalIgnoreCase) == 0);
+ Debug.Assert(!string.IsNullOrEmpty(source));
+ Debug.Assert(target != null);
+ Debug.Assert((options & CompareOptions.OrdinalIgnoreCase) == 0);
// TODO: Consider moving this up to the relevent APIs we need to ensure this behavior for
// and add a precondition that target is not empty.
@@ -200,9 +201,9 @@ namespace System.Globalization
private int LastIndexOfCore(string source, string target, int startIndex, int count, CompareOptions options)
{
- Contract.Assert(!string.IsNullOrEmpty(source));
- Contract.Assert(target != null);
- Contract.Assert((options & CompareOptions.OrdinalIgnoreCase) == 0);
+ Debug.Assert(!string.IsNullOrEmpty(source));
+ Debug.Assert(target != null);
+ Debug.Assert((options & CompareOptions.OrdinalIgnoreCase) == 0);
// TODO: Consider moving this up to the relevent APIs we need to ensure this behavior for
// and add a precondition that target is not empty.
@@ -234,9 +235,9 @@ namespace System.Globalization
private bool StartsWith(string source, string prefix, CompareOptions options)
{
- Contract.Assert(!string.IsNullOrEmpty(source));
- Contract.Assert(!string.IsNullOrEmpty(prefix));
- Contract.Assert((options & (CompareOptions.Ordinal | CompareOptions.OrdinalIgnoreCase)) == 0);
+ 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,
@@ -249,9 +250,9 @@ namespace System.Globalization
private bool EndsWith(string source, string suffix, CompareOptions options)
{
- Contract.Assert(!string.IsNullOrEmpty(source));
- Contract.Assert(!string.IsNullOrEmpty(suffix));
- Contract.Assert((options & (CompareOptions.Ordinal | CompareOptions.OrdinalIgnoreCase)) == 0);
+ 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,
@@ -280,14 +281,10 @@ namespace System.Globalization
int sourceStartIndex = findLastIndex ? startIndex - sourceCount + 1 : startIndex;
-#if !TEST_CODEGEN_OPTIMIZATION
fixed (char* pSource = source, spTarget = target)
{
char* spSubSource = pSource + sourceStartIndex;
-#else
- String.StringPointer spSubSource = source.GetStringPointer(sourceStartIndex);
- String.StringPointer spTarget = target.GetStringPointer();
-#endif
+
if (findLastIndex)
{
int startPattern = (sourceCount - 1) - targetCount + 1;
@@ -347,11 +344,29 @@ namespace System.Globalization
retValue += startIndex;
}
}
-#if !TEST_CODEGEN_OPTIMIZATION
}
return retValue;
-#endif // TEST_CODEGEN_OPTIMIZATION
+ }
+
+ private unsafe SortKey CreateSortKey(String source, CompareOptions options)
+ {
+ if (source==null) { throw new ArgumentNullException(nameof(source)); }
+ Contract.EndContractBlock();
+
+ if ((options & ValidSortkeyCtorMaskOffFlags) != 0)
+ {
+ throw new ArgumentException(SR.Argument_InvalidFlag, nameof(options));
+ }
+
+ throw new NotImplementedException();
+ }
+
+ private static unsafe bool IsSortable(char *text, int length)
+ {
+ // CompareInfo c = CultureInfo.InvariantCulture.CompareInfo;
+ // return (InternalIsSortable(c.m_dataHandle, c.m_handleOrigin, c.m_sortName, text, text.Length));
+ throw new NotImplementedException();
}
private const int COMPARE_OPTIONS_ORDINAL = 0x40000000; // Ordinal
@@ -381,7 +396,7 @@ namespace System.Globalization
// Suffix & Prefix shouldn't use this, make sure to turn off the NORM_LINGUISTIC_CASING flag
if (options == CompareOptions.Ordinal) { nativeCompareFlags = COMPARE_OPTIONS_ORDINAL; }
- Contract.Assert(((options & ~(CompareOptions.IgnoreCase |
+ Debug.Assert(((options & ~(CompareOptions.IgnoreCase |
CompareOptions.IgnoreKanaType |
CompareOptions.IgnoreNonSpace |
CompareOptions.IgnoreSymbols |
@@ -391,5 +406,10 @@ namespace System.Globalization
return nativeCompareFlags;
}
+
+ private SortVersion GetSortVersion()
+ {
+ throw new NotImplementedException();
+ }
}
}
diff --git a/src/mscorlib/corefx/System/Globalization/CompareInfo.cs b/src/mscorlib/corefx/System/Globalization/CompareInfo.cs
index 77778af23c..64dbfe84f7 100644
--- a/src/mscorlib/corefx/System/Globalization/CompareInfo.cs
+++ b/src/mscorlib/corefx/System/Globalization/CompareInfo.cs
@@ -12,20 +12,15 @@
//
////////////////////////////////////////////////////////////////////////////
-using System;
-using System.Collections;
-using System.Collections.Generic;
+using System.Reflection;
+using System.Diagnostics;
using System.Diagnostics.Contracts;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
using System.Runtime.Serialization;
-using System.Threading;
namespace System.Globalization
{
[Flags]
[Serializable]
- [System.Runtime.InteropServices.ComVisible(true)]
public enum CompareOptions
{
None = 0x00000000,
@@ -40,7 +35,6 @@ namespace System.Globalization
}
[Serializable]
- [System.Runtime.InteropServices.ComVisible(true)]
public partial class CompareInfo : IDeserializationCallback
{
// Mask used to check if IndexOf()/LastIndexOf()/IsPrefix()/IsPostfix() has the right flags.
@@ -58,6 +52,11 @@ namespace System.Globalization
~(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);
+
//
// 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.
@@ -69,6 +68,86 @@ namespace System.Globalization
[NonSerialized]
private String _sortName; // The name that defines our behavior
+ [OptionalField(VersionAdded = 3)]
+ private SortVersion _sortVersion;
+
+ /*=================================GetCompareInfo==========================
+ **Action: Get the CompareInfo constructed from the data table in the specified assembly for the specified culture.
+ ** Warning: The assembly versioning mechanism is dead!
+ **Returns: The CompareInfo for the specified culture.
+ **Arguments:
+ ** culture the ID of the culture
+ ** assembly the assembly which contains the sorting table.
+ **Exceptions:
+ ** ArugmentNullException when the assembly is null
+ ** ArgumentException if culture is invalid.
+ ============================================================================*/
+ // Assembly constructor should be deprecated, we don't act on the assembly information any more
+ 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);
+ }
+ Contract.EndContractBlock();
+
+ return GetCompareInfo(culture);
+ }
+
+ /*=================================GetCompareInfo==========================
+ **Action: 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.
+ **Returns: The CompareInfo for the specified culture.
+ **Arguments:
+ ** name the name of the culture
+ ** assembly the assembly which contains the sorting table.
+ **Exceptions:
+ ** ArugmentNullException when the assembly is null
+ ** ArgumentException if name is invalid.
+ ============================================================================*/
+ // Assembly constructor should be deprecated, we don't act on the assembly information any more
+ public static CompareInfo GetCompareInfo(String name, Assembly assembly)
+ {
+ if (name == null || assembly == null)
+ {
+ throw new ArgumentNullException(name == null ? nameof(name) : nameof(assembly));
+ }
+ Contract.EndContractBlock();
+
+ if (assembly != typeof(Object).Module.Assembly)
+ {
+ throw new ArgumentException(SR.Argument_OnlyMscorlib);
+ }
+
+ return GetCompareInfo(name);
+ }
+
+ /*=================================GetCompareInfo==========================
+ **Action: Get the CompareInfo for the specified culture.
+ ** This method is provided for ease of integration with NLS-based software.
+ **Returns: The CompareInfo for the specified culture.
+ **Arguments:
+ ** culture the ID of the culture.
+ **Exceptions:
+ ** ArgumentException if culture is invalid.
+ ============================================================================*/
+ // People really shouldn't be calling LCID versions, no custom support
+ public static CompareInfo GetCompareInfo(int culture)
+ {
+ if (CultureData.IsCustomCultureId(culture))
+ {
+ // Customized culture cannot be created by the LCID.
+ throw new ArgumentException(SR.Argument_CustomCultureCannotBePassedByNumber, nameof(culture));
+ }
+
+ return CultureInfo.GetCultureInfo(culture).CompareInfo;
+ }
+
/*=================================GetCompareInfo==========================
**Action: Get the CompareInfo for the specified culture.
**Returns: The CompareInfo for the specified culture.
@@ -82,13 +161,40 @@ namespace System.Globalization
{
if (name == null)
{
- throw new ArgumentNullException("name");
+ throw new ArgumentNullException(nameof(name));
}
Contract.EndContractBlock();
return CultureInfo.GetCultureInfo(name).CompareInfo;
}
+ public static unsafe bool IsSortable(char ch)
+ {
+ char *pChar = &ch;
+ return IsSortable(pChar, 1);
+ }
+
+ public static unsafe bool IsSortable(string text)
+ {
+ if (text == null)
+ {
+ // A null param is invalid here.
+ throw new ArgumentNullException(nameof(text));
+ }
+
+ if (0 == text.Length)
+ {
+ // A zero length string is not invalid, but it is also not sortable.
+ return (false);
+ }
+
+ fixed (char *pChar = text)
+ {
+ return IsSortable(pChar, text.Length);
+ }
+ }
+
+
[OnDeserializing]
private void OnDeserializing(StreamingContext ctx)
{
@@ -130,12 +236,11 @@ namespace System.Globalization
//
////////////////////////////////////////////////////////////////////////
- [System.Runtime.InteropServices.ComVisible(false)]
public virtual String Name
{
get
{
- Contract.Assert(_name != null, "CompareInfo.Name Expected _name to be set");
+ Debug.Assert(_name != null, "CompareInfo.Name Expected _name to be set");
if (_name == "zh-CHT" || _name == "zh-CHS")
{
return _name;
@@ -173,14 +278,14 @@ namespace System.Globalization
{
if (options != CompareOptions.Ordinal)
{
- throw new ArgumentException(SR.Argument_CompareOptionOrdinal, "options");
+ throw new ArgumentException(SR.Argument_CompareOptionOrdinal, nameof(options));
}
return String.CompareOrdinal(string1, string2);
}
if ((options & ValidCompareMaskOffFlags) != 0)
{
- throw new ArgumentException(SR.Argument_InvalidFlag, "options");
+ throw new ArgumentException(SR.Argument_InvalidFlag, nameof(options));
}
//Our paradigm is that null sorts less than any other string and
@@ -247,31 +352,31 @@ namespace System.Globalization
// Verify inputs
if (length1 < 0 || length2 < 0)
{
- throw new ArgumentOutOfRangeException((length1 < 0) ? "length1" : "length2", SR.ArgumentOutOfRange_NeedPosNum);
+ throw new ArgumentOutOfRangeException((length1 < 0) ? nameof(length1) : nameof(length2), SR.ArgumentOutOfRange_NeedPosNum);
}
if (offset1 < 0 || offset2 < 0)
{
- throw new ArgumentOutOfRangeException((offset1 < 0) ? "offset1" : "offset2", SR.ArgumentOutOfRange_NeedPosNum);
+ throw new ArgumentOutOfRangeException((offset1 < 0) ? nameof(offset1) : nameof(offset2), SR.ArgumentOutOfRange_NeedPosNum);
}
if (offset1 > (string1 == null ? 0 : string1.Length) - length1)
{
- throw new ArgumentOutOfRangeException("string1", SR.ArgumentOutOfRange_OffsetLength);
+ throw new ArgumentOutOfRangeException(nameof(string1), SR.ArgumentOutOfRange_OffsetLength);
}
if (offset2 > (string2 == null ? 0 : string2.Length) - length2)
{
- throw new ArgumentOutOfRangeException("string2", SR.ArgumentOutOfRange_OffsetLength);
+ throw new ArgumentOutOfRangeException(nameof(string2), SR.ArgumentOutOfRange_OffsetLength);
}
if ((options & CompareOptions.Ordinal) != 0)
{
if (options != CompareOptions.Ordinal)
{
throw new ArgumentException(SR.Argument_CompareOptionOrdinal,
- "options");
+ nameof(options));
}
}
else if ((options & ValidCompareMaskOffFlags) != 0)
{
- throw new ArgumentException(SR.Argument_InvalidFlag, "options");
+ throw new ArgumentException(SR.Argument_InvalidFlag, nameof(options));
}
//
@@ -318,8 +423,8 @@ namespace System.Globalization
//
internal static unsafe int CompareOrdinalIgnoreCase(string strA, int indexA, int lengthA, string strB, int indexB, int lengthB)
{
- Contract.Assert(indexA + lengthA <= strA.Length);
- Contract.Assert(indexB + lengthB <= strB.Length);
+ Debug.Assert(indexA + lengthA <= strA.Length);
+ Debug.Assert(indexB + lengthB <= strB.Length);
int length = Math.Min(lengthA, lengthB);
int range = length;
@@ -375,7 +480,7 @@ namespace System.Globalization
{
if (source == null || prefix == null)
{
- throw new ArgumentNullException((source == null ? "source" : "prefix"),
+ throw new ArgumentNullException((source == null ? nameof(source) : nameof(prefix)),
SR.ArgumentNull_String);
}
Contract.EndContractBlock();
@@ -402,7 +507,7 @@ namespace System.Globalization
if ((options & ValidIndexMaskOffFlags) != 0)
{
- throw new ArgumentException(SR.Argument_InvalidFlag, "options");
+ throw new ArgumentException(SR.Argument_InvalidFlag, nameof(options));
}
return StartsWith(source, prefix, options);
@@ -425,7 +530,7 @@ namespace System.Globalization
{
if (source == null || suffix == null)
{
- throw new ArgumentNullException((source == null ? "source" : "suffix"),
+ throw new ArgumentNullException((source == null ? nameof(source) : nameof(suffix)),
SR.ArgumentNull_String);
}
Contract.EndContractBlock();
@@ -452,7 +557,7 @@ namespace System.Globalization
if ((options & ValidIndexMaskOffFlags) != 0)
{
- throw new ArgumentException(SR.Argument_InvalidFlag, "options");
+ throw new ArgumentException(SR.Argument_InvalidFlag, nameof(options));
}
return EndsWith(source, suffix, options);
@@ -481,7 +586,7 @@ namespace System.Globalization
public unsafe virtual int IndexOf(String source, char value)
{
if (source == null)
- throw new ArgumentNullException("source");
+ throw new ArgumentNullException(nameof(source));
Contract.EndContractBlock();
return IndexOf(source, value, 0, source.Length, CompareOptions.None);
@@ -491,7 +596,7 @@ namespace System.Globalization
public unsafe virtual int IndexOf(String source, String value)
{
if (source == null)
- throw new ArgumentNullException("source");
+ throw new ArgumentNullException(nameof(source));
Contract.EndContractBlock();
return IndexOf(source, value, 0, source.Length, CompareOptions.None);
@@ -501,7 +606,7 @@ namespace System.Globalization
public unsafe virtual int IndexOf(String source, char value, CompareOptions options)
{
if (source == null)
- throw new ArgumentNullException("source");
+ throw new ArgumentNullException(nameof(source));
Contract.EndContractBlock();
return IndexOf(source, value, 0, source.Length, options);
@@ -511,17 +616,34 @@ namespace System.Globalization
public unsafe virtual int IndexOf(String source, String value, CompareOptions options)
{
if (source == null)
- throw new ArgumentNullException("source");
+ throw new ArgumentNullException(nameof(source));
Contract.EndContractBlock();
return IndexOf(source, value, 0, source.Length, options);
}
+ public unsafe virtual int IndexOf(String source, char value, int startIndex)
+ {
+ if (source == null)
+ throw new ArgumentNullException(nameof(source));
+ Contract.EndContractBlock();
+
+ return IndexOf(source, value, startIndex, source.Length - startIndex, CompareOptions.None);
+ }
+
+ public unsafe virtual int IndexOf(String source, String value, int startIndex)
+ {
+ if (source == null)
+ throw new ArgumentNullException(nameof(source));
+ Contract.EndContractBlock();
+
+ return IndexOf(source, value, startIndex, source.Length - startIndex, CompareOptions.None);
+ }
public unsafe virtual int IndexOf(String source, char value, int startIndex, CompareOptions options)
{
if (source == null)
- throw new ArgumentNullException("source");
+ throw new ArgumentNullException(nameof(source));
Contract.EndContractBlock();
return IndexOf(source, value, startIndex, source.Length - startIndex, options);
@@ -531,7 +653,7 @@ namespace System.Globalization
public unsafe virtual int IndexOf(String source, String value, int startIndex, CompareOptions options)
{
if (source == null)
- throw new ArgumentNullException("source");
+ throw new ArgumentNullException(nameof(source));
Contract.EndContractBlock();
return IndexOf(source, value, startIndex, source.Length - startIndex, options);
@@ -553,13 +675,13 @@ namespace System.Globalization
{
// Validate inputs
if (source == null)
- throw new ArgumentNullException("source");
+ throw new ArgumentNullException(nameof(source));
if (startIndex < 0 || startIndex > source.Length)
- throw new ArgumentOutOfRangeException("startIndex", SR.ArgumentOutOfRange_Index);
+ throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_Index);
if (count < 0 || startIndex > source.Length - count)
- throw new ArgumentOutOfRangeException("count", SR.ArgumentOutOfRange_Count);
+ throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_Count);
Contract.EndContractBlock();
if (options == CompareOptions.OrdinalIgnoreCase)
@@ -570,7 +692,7 @@ namespace System.Globalization
// Validate CompareOptions
// Ordinal can't be selected with other flags
if ((options & ValidIndexMaskOffFlags) != 0 && (options != CompareOptions.Ordinal))
- throw new ArgumentException(SR.Argument_InvalidFlag, "options");
+ throw new ArgumentException(SR.Argument_InvalidFlag, nameof(options));
return IndexOfCore(source, new string(value, 1), startIndex, count, options);
}
@@ -580,13 +702,13 @@ namespace System.Globalization
{
// Validate inputs
if (source == null)
- throw new ArgumentNullException("source");
+ throw new ArgumentNullException(nameof(source));
if (value == null)
- throw new ArgumentNullException("value");
+ throw new ArgumentNullException(nameof(value));
if (startIndex > source.Length)
{
- throw new ArgumentOutOfRangeException("startIndex", SR.ArgumentOutOfRange_Index);
+ throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_Index);
}
Contract.EndContractBlock();
@@ -603,11 +725,11 @@ namespace System.Globalization
if (startIndex < 0)
{
- throw new ArgumentOutOfRangeException("startIndex", SR.ArgumentOutOfRange_Index);
+ throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_Index);
}
if (count < 0 || startIndex > source.Length - count)
- throw new ArgumentOutOfRangeException("count", SR.ArgumentOutOfRange_Count);
+ throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_Count);
if (options == CompareOptions.OrdinalIgnoreCase)
{
@@ -617,7 +739,7 @@ namespace System.Globalization
// Validate CompareOptions
// Ordinal can't be selected with other flags
if ((options & ValidIndexMaskOffFlags) != 0 && (options != CompareOptions.Ordinal))
- throw new ArgumentException(SR.Argument_InvalidFlag, "options");
+ throw new ArgumentException(SR.Argument_InvalidFlag, nameof(options));
return IndexOfCore(source, value, startIndex, count, options);
}
@@ -639,7 +761,7 @@ namespace System.Globalization
public unsafe virtual int LastIndexOf(String source, char value)
{
if (source == null)
- throw new ArgumentNullException("source");
+ throw new ArgumentNullException(nameof(source));
Contract.EndContractBlock();
// Can't start at negative index, so make sure we check for the length == 0 case.
@@ -651,7 +773,7 @@ namespace System.Globalization
public virtual int LastIndexOf(String source, String value)
{
if (source == null)
- throw new ArgumentNullException("source");
+ throw new ArgumentNullException(nameof(source));
Contract.EndContractBlock();
// Can't start at negative index, so make sure we check for the length == 0 case.
@@ -663,7 +785,7 @@ namespace System.Globalization
public virtual int LastIndexOf(String source, char value, CompareOptions options)
{
if (source == null)
- throw new ArgumentNullException("source");
+ throw new ArgumentNullException(nameof(source));
Contract.EndContractBlock();
// Can't start at negative index, so make sure we check for the length == 0 case.
@@ -674,7 +796,7 @@ namespace System.Globalization
public unsafe virtual int LastIndexOf(String source, String value, CompareOptions options)
{
if (source == null)
- throw new ArgumentNullException("source");
+ throw new ArgumentNullException(nameof(source));
Contract.EndContractBlock();
// Can't start at negative index, so make sure we check for the length == 0 case.
@@ -682,6 +804,16 @@ namespace System.Globalization
source.Length, options);
}
+ public unsafe virtual int LastIndexOf(String source, char value, int startIndex)
+ {
+ return LastIndexOf(source, value, startIndex, startIndex + 1, CompareOptions.None);
+ }
+
+
+ public unsafe virtual int LastIndexOf(String source, String value, int startIndex)
+ {
+ return LastIndexOf(source, value, startIndex, startIndex + 1, CompareOptions.None);
+ }
public unsafe virtual int LastIndexOf(String source, char value, int startIndex, CompareOptions options)
{
@@ -711,7 +843,7 @@ namespace System.Globalization
{
// Verify Arguments
if (source == null)
- throw new ArgumentNullException("source");
+ throw new ArgumentNullException(nameof(source));
Contract.EndContractBlock();
// Validate CompareOptions
@@ -719,7 +851,7 @@ namespace System.Globalization
if ((options & ValidIndexMaskOffFlags) != 0 &&
(options != CompareOptions.Ordinal) &&
(options != CompareOptions.OrdinalIgnoreCase))
- throw new ArgumentException(SR.Argument_InvalidFlag, "options");
+ throw new ArgumentException(SR.Argument_InvalidFlag, nameof(options));
// Special case for 0 length input strings
if (source.Length == 0 && (startIndex == -1 || startIndex == 0))
@@ -727,7 +859,7 @@ namespace System.Globalization
// Make sure we're not out of range
if (startIndex < 0 || startIndex > source.Length)
- throw new ArgumentOutOfRangeException("startIndex", SR.ArgumentOutOfRange_Index);
+ throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_Index);
// Make sure that we allow startIndex == source.Length
if (startIndex == source.Length)
@@ -739,7 +871,7 @@ namespace System.Globalization
// 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("count", SR.ArgumentOutOfRange_Count);
+ throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_Count);
if (options == CompareOptions.OrdinalIgnoreCase)
{
@@ -754,9 +886,9 @@ namespace System.Globalization
{
// Verify Arguments
if (source == null)
- throw new ArgumentNullException("source");
+ throw new ArgumentNullException(nameof(source));
if (value == null)
- throw new ArgumentNullException("value");
+ throw new ArgumentNullException(nameof(value));
Contract.EndContractBlock();
// Validate CompareOptions
@@ -764,7 +896,7 @@ namespace System.Globalization
if ((options & ValidIndexMaskOffFlags) != 0 &&
(options != CompareOptions.Ordinal) &&
(options != CompareOptions.OrdinalIgnoreCase))
- throw new ArgumentException(SR.Argument_InvalidFlag, "options");
+ throw new ArgumentException(SR.Argument_InvalidFlag, nameof(options));
// Special case for 0 length input strings
if (source.Length == 0 && (startIndex == -1 || startIndex == 0))
@@ -772,7 +904,7 @@ namespace System.Globalization
// Make sure we're not out of range
if (startIndex < 0 || startIndex > source.Length)
- throw new ArgumentOutOfRangeException("startIndex", SR.ArgumentOutOfRange_Index);
+ throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_Index);
// Make sure that we allow startIndex == source.Length
if (startIndex == source.Length)
@@ -788,7 +920,7 @@ namespace System.Globalization
// 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("count", SR.ArgumentOutOfRange_Count);
+ throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_Count);
if (options == CompareOptions.OrdinalIgnoreCase)
{
@@ -798,8 +930,24 @@ namespace System.Globalization
return LastIndexOfCore(source, value, startIndex, count, options);
}
+ ////////////////////////////////////////////////////////////////////////
+ //
+ // GetSortKey
+ //
+ // Gets the SortKey for the given string with the given options.
+ //
+ ////////////////////////////////////////////////////////////////////////
+ public unsafe virtual SortKey GetSortKey(String source, CompareOptions options)
+ {
+ return CreateSortKey(source, options);
+ }
+ public unsafe virtual SortKey GetSortKey(String source)
+ {
+ return CreateSortKey(source, CompareOptions.None);
+ }
+
////////////////////////////////////////////////////////////////////////
//
// Equals
@@ -872,12 +1020,12 @@ namespace System.Globalization
//
if (null == source)
{
- throw new ArgumentNullException("source");
+ throw new ArgumentNullException(nameof(source));
}
if ((options & ValidHashCodeOfStringMaskOffFlags) != 0)
{
- throw new ArgumentException(SR.Argument_InvalidFlag, "options");
+ throw new ArgumentException(SR.Argument_InvalidFlag, nameof(options));
}
Contract.EndContractBlock();
@@ -888,7 +1036,7 @@ namespace System.Globalization
{
if (source == null)
{
- throw new ArgumentNullException("source");
+ throw new ArgumentNullException(nameof(source));
}
if (options == CompareOptions.Ordinal)
@@ -921,5 +1069,26 @@ namespace System.Globalization
{
return ("CompareInfo - " + this.Name);
}
+
+ public SortVersion Version
+ {
+ get
+ {
+ if (_sortVersion == null)
+ {
+ _sortVersion = GetSortVersion();
+ }
+
+ return _sortVersion;
+ }
+ }
+
+ public int LCID
+ {
+ get
+ {
+ return CultureInfo.GetCultureInfo(Name).LCID;
+ }
+ }
}
}
diff --git a/src/mscorlib/corefx/System/Globalization/CultureData.Unix.cs b/src/mscorlib/corefx/System/Globalization/CultureData.Unix.cs
index 58aae2f40b..7f2f17d9f5 100644
--- a/src/mscorlib/corefx/System/Globalization/CultureData.Unix.cs
+++ b/src/mscorlib/corefx/System/Globalization/CultureData.Unix.cs
@@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
+using System.Diagnostics;
using System.Diagnostics.Contracts;
using System.Runtime.InteropServices;
using System.Security;
@@ -17,7 +18,8 @@ namespace System.Globalization
const int ICU_ULOC_KEYWORD_AND_VALUES_CAPACITY = 100; // max size of keyword or value
const int ICU_ULOC_FULLNAME_CAPACITY = 157; // max size of locale name
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.
@@ -25,8 +27,8 @@ namespace System.Globalization
[SecuritySafeCritical]
private unsafe bool InitCultureData()
{
- Contract.Assert(_sRealName != null);
-
+ Debug.Assert(_sRealName != null);
+
string alternateSortName = string.Empty;
string realNameBuffer = _sRealName;
@@ -66,23 +68,21 @@ namespace System.Globalization
_sName = _sWindowsName;
}
_sRealName = _sName;
- _sSpecificCulture = _sRealName; // we don't attempt to find a non-neutral locale if a neutral is passed in (unlike win32)
_iLanguage = this.ILANGUAGE;
if (_iLanguage == 0)
{
- _iLanguage = LOCALE_CUSTOM_UNSPECIFIED;
+ _iLanguage = CultureInfo.LOCALE_CUSTOM_UNSPECIFIED;
}
_bNeutral = (this.SISO3166CTRYNAME.Length == 0);
-
+
+ _sSpecificCulture = _bNeutral ? LocaleData.GetSpecificCultureName(_sRealName) : _sRealName;
+
// Remove the sort from sName unless custom culture
- if (!_bNeutral)
+ if (index>0 && !_bNeutral && !IsCustomCultureId(_iLanguage))
{
- if (!IsCustomCultureId(_iLanguage))
- {
- _sName = _sWindowsName.Substring(0, index);
- }
+ _sName = _sWindowsName.Substring(0, index);
}
return true;
}
@@ -120,10 +120,10 @@ namespace System.Globalization
windowsName = StringBuilderCache.GetStringAndRelease(sb); // the name passed to subsequent ICU calls
return true;
}
-
+
private string GetLocaleInfo(LocaleStringData type)
{
- Contract.Assert(_sWindowsName != null, "[CultureData.GetLocaleInfo] Expected _sWindowsName to be populated already");
+ Debug.Assert(_sWindowsName != null, "[CultureData.GetLocaleInfo] Expected _sWindowsName to be populated already");
return GetLocaleInfo(_sWindowsName, type);
}
@@ -132,7 +132,7 @@ namespace System.Globalization
[SecuritySafeCritical]
private string GetLocaleInfo(string localeName, LocaleStringData type)
{
- Contract.Assert(localeName != null, "[CultureData.GetLocaleInfo] Expected localeName to be not be null");
+ Debug.Assert(localeName != null, "[CultureData.GetLocaleInfo] Expected localeName to be not be null");
switch (type)
{
@@ -149,7 +149,7 @@ namespace System.Globalization
{
// Failed, just use empty string
StringBuilderCache.Release(sb);
- Contract.Assert(false, "[CultureData.GetLocaleInfo(LocaleStringData)] Failed");
+ Debug.Assert(false, "[CultureData.GetLocaleInfo(LocaleStringData)] Failed");
return String.Empty;
}
return StringBuilderCache.GetStringAndRelease(sb);
@@ -158,7 +158,7 @@ namespace System.Globalization
[SecuritySafeCritical]
private int GetLocaleInfo(LocaleNumberData type)
{
- Contract.Assert(_sWindowsName != null, "[CultureData.GetLocaleInfo(LocaleNumberData)] Expected _sWindowsName to be populated already");
+ Debug.Assert(_sWindowsName != null, "[CultureData.GetLocaleInfo(LocaleNumberData)] Expected _sWindowsName to be populated already");
switch (type)
{
@@ -173,7 +173,7 @@ namespace System.Globalization
if (!result)
{
// Failed, just use 0
- Contract.Assert(false, "[CultureData.GetLocaleInfo(LocaleNumberData)] failed");
+ Debug.Assert(false, "[CultureData.GetLocaleInfo(LocaleNumberData)] failed");
}
return value;
@@ -182,14 +182,14 @@ namespace System.Globalization
[SecuritySafeCritical]
private int[] GetLocaleInfo(LocaleGroupingData type)
{
- Contract.Assert(_sWindowsName != null, "[CultureData.GetLocaleInfo(LocaleGroupingData)] Expected _sWindowsName to be populated already");
+ Debug.Assert(_sWindowsName != null, "[CultureData.GetLocaleInfo(LocaleGroupingData)] Expected _sWindowsName to be populated already");
int primaryGroupingSize = 0;
int secondaryGroupingSize = 0;
bool result = Interop.GlobalizationInterop.GetLocaleInfoGroupingSizes(_sWindowsName, (uint)type, ref primaryGroupingSize, ref secondaryGroupingSize);
if (!result)
{
- Contract.Assert(false, "[CultureData.GetLocaleInfo(LocaleGroupingData type)] failed");
+ Debug.Assert(false, "[CultureData.GetLocaleInfo(LocaleGroupingData type)] failed");
}
if (secondaryGroupingSize == 0)
@@ -208,7 +208,7 @@ namespace System.Globalization
[SecuritySafeCritical]
private string GetTimeFormatString(bool shortFormat)
{
- Contract.Assert(_sWindowsName != null, "[CultureData.GetTimeFormatString(bool shortFormat)] Expected _sWindowsName to be populated already");
+ Debug.Assert(_sWindowsName != null, "[CultureData.GetTimeFormatString(bool shortFormat)] Expected _sWindowsName to be populated already");
StringBuilder sb = StringBuilderCache.Acquire(ICU_ULOC_KEYWORD_AND_VALUES_CAPACITY);
@@ -217,7 +217,7 @@ namespace System.Globalization
{
// Failed, just use empty string
StringBuilderCache.Release(sb);
- Contract.Assert(false, "[CultureData.GetTimeFormatString(bool shortFormat)] Failed");
+ Debug.Assert(false, "[CultureData.GetTimeFormatString(bool shortFormat)] Failed");
return String.Empty;
}
@@ -300,5 +300,127 @@ namespace System.Globalization
return StringBuilderCache.GetStringAndRelease(sb);
}
+
+ private static string LCIDToLocaleName(int culture)
+ {
+ return LocaleData.LCIDToLocaleName(culture);
+ }
+
+ private static int LocaleNameToLCID(string cultureName)
+ {
+ 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.IDEFAULTANSICODEPAGE : ansiCodePage;
+ }
+
+ private static int GetOemCodePage(string cultureName)
+ {
+ int oemCodePage = LocaleData.GetLocaleDataNumericPart(cultureName, LocaleDataParts.OemCodePage);
+ return oemCodePage == -1 ? CultureData.Invariant.IDEFAULTOEMCODEPAGE : oemCodePage;
+ }
+
+ private static int GetMacCodePage(string cultureName)
+ {
+ int macCodePage = LocaleData.GetLocaleDataNumericPart(cultureName, LocaleDataParts.MacCodePage);
+ return macCodePage == -1 ? CultureData.Invariant.IDEFAULTMACCODEPAGE : macCodePage;
+ }
+
+ private static int GetEbcdicCodePage(string cultureName)
+ {
+ int ebcdicCodePage = LocaleData.GetLocaleDataNumericPart(cultureName, LocaleDataParts.EbcdicCodePage);
+ return ebcdicCodePage == -1 ? CultureData.Invariant.IDEFAULTEBCDICCODEPAGE : ebcdicCodePage;
+ }
+
+ private static int GetGeoId(string cultureName)
+ {
+ int geoId = LocaleData.GetLocaleDataNumericPart(cultureName, LocaleDataParts.GeoId);
+ return geoId == -1 ? CultureData.Invariant.IGEOID : 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)
+ {
+ string langName = LocaleData.GetThreeLetterWindowsLangageName(cultureName);
+ return langName == null ? "ZZZ" /* default lang name */ : langName;
+ }
+
+ private static CultureInfo[] EnumCultures(CultureTypes types)
+ {
+ if ((types & (CultureTypes.NeutralCultures | CultureTypes.SpecificCultures)) == 0)
+ {
+ return Array.Empty<CultureInfo>();
+ }
+
+ int bufferLength = Interop.GlobalizationInterop.GetLocales(null, 0);
+ if (bufferLength <= 0)
+ {
+ return Array.Empty<CultureInfo>();
+ }
+
+ Char [] chars = new Char[bufferLength];
+
+ bufferLength = Interop.GlobalizationInterop.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 IsFramework // not applicable on Linux based systems
+ {
+ get { return false; }
+ }
+
+ internal bool IsWin32Installed // not applicable on Linux based systems
+ {
+ get { return false; }
+ }
+
+ internal bool IsReplacementCulture // not applicable on Linux based systems
+ {
+ get { return false; }
+ }
}
}
diff --git a/src/mscorlib/corefx/System/Globalization/CultureData.Windows.cs b/src/mscorlib/corefx/System/Globalization/CultureData.Windows.cs
index 9969ecbd81..d1c99da607 100644
--- a/src/mscorlib/corefx/System/Globalization/CultureData.Windows.cs
+++ b/src/mscorlib/corefx/System/Globalization/CultureData.Windows.cs
@@ -3,10 +3,13 @@
// See the LICENSE file in the project root for more information.
using System.Collections.Generic;
-using System.Diagnostics.Contracts;
+using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Text;
+
+#if ENABLE_WINRT
using Internal.Runtime.Augments;
+#endif
namespace System.Globalization
{
@@ -158,7 +161,7 @@ namespace System.Globalization
private string GetLocaleInfo(LocaleStringData type)
{
- Contract.Assert(_sWindowsName != null, "[CultureData.DoGetLocaleInfo] Expected _sWindowsName to be populated by already");
+ Debug.Assert(_sWindowsName != null, "[CultureData.DoGetLocaleInfo] Expected _sWindowsName to be populated by already");
return GetLocaleInfo(_sWindowsName, type);
}
@@ -183,7 +186,7 @@ namespace System.Globalization
// Ask OS for data, note that we presume it returns success, so we have to know that
// sWindowsName is valid before calling.
- Contract.Assert(_sWindowsName != null, "[CultureData.DoGetLocaleInfoInt] Expected _sWindowsName to be populated by already");
+ Debug.Assert(_sWindowsName != null, "[CultureData.DoGetLocaleInfoInt] Expected _sWindowsName to be populated by already");
int result = Interop.mincore.GetLocaleInfoExInt(_sWindowsName, lctype);
return result;
@@ -203,7 +206,7 @@ namespace System.Globalization
private int GetFirstDayOfWeek()
{
- Contract.Assert(_sWindowsName != null, "[CultureData.DoGetLocaleInfoInt] Expected _sWindowsName to be populated by already");
+ Debug.Assert(_sWindowsName != null, "[CultureData.DoGetLocaleInfoInt] Expected _sWindowsName to be populated by already");
const uint LOCALE_IFIRSTDAYOFWEEK = 0x0000100C;
@@ -216,7 +219,7 @@ namespace System.Globalization
private String[] GetTimeFormats()
{
// Note that this gets overrides for us all the time
- Contract.Assert(_sWindowsName != null, "[CultureData.DoEnumTimeFormats] Expected _sWindowsName to be populated by already");
+ Debug.Assert(_sWindowsName != null, "[CultureData.DoEnumTimeFormats] Expected _sWindowsName to be populated by already");
String[] result = ReescapeWin32Strings(nativeEnumTimeFormats(_sWindowsName, 0, UseUserOverride));
return result;
@@ -225,7 +228,7 @@ namespace System.Globalization
private String[] GetShortTimeFormats()
{
// Note that this gets overrides for us all the time
- Contract.Assert(_sWindowsName != null, "[CultureData.DoEnumShortTimeFormats] Expected _sWindowsName to be populated by already");
+ Debug.Assert(_sWindowsName != null, "[CultureData.DoEnumShortTimeFormats] Expected _sWindowsName to be populated by already");
String[] result = ReescapeWin32Strings(nativeEnumTimeFormats(_sWindowsName, TIME_NOSECONDS, UseUserOverride));
return result;
@@ -235,7 +238,7 @@ namespace System.Globalization
// region name match the requested region name
private static CultureData GetCultureDataFromRegionName(String regionName)
{
- Contract.Assert(regionName != null);
+ Debug.Assert(regionName != null);
const uint LOCALE_SUPPLEMENTAL = 0x00000002;
const uint LOCALE_SPECIFICDATA = 0x00000020;
@@ -264,26 +267,64 @@ namespace System.Globalization
return null;
}
- private static string GetLanguageDisplayName(string cultureName)
+ private string GetLanguageDisplayName(string cultureName)
{
+#if ENABLE_WINRT
return WinRTInterop.Callbacks.GetLanguageDisplayName(cultureName);
+#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 = GetUserDefaultCulture()) != null) &&
+ !CultureInfo.DefaultThreadCurrentUICulture.Name.Equals(ci.Name))
+ {
+ return SNATIVEDISPLAYNAME;
+ }
+ else
+ {
+ return GetLocaleInfo(cultureName, LocaleStringData.LocalizedDisplayName);
+ }
+#endif // ENABLE_WINRT
}
- private static string GetRegionDisplayName(string isoCountryCode)
+ private string GetRegionDisplayName(string isoCountryCode)
{
+#if ENABLE_WINRT
return WinRTInterop.Callbacks.GetRegionDisplayName(isoCountryCode);
+#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 = GetUserDefaultCulture()) != null) &&
+ !CultureInfo.DefaultThreadCurrentUICulture.Name.Equals(ci.Name))
+ {
+ return SNATIVECOUNTRY;
+ }
+ else
+ {
+ return GetLocaleInfo(LocaleStringData.LocalizedCountryName);
+ }
+#endif // ENABLE_WINRT
}
private static CultureInfo GetUserDefaultCulture()
{
+#if ENABLE_WINRT
return (CultureInfo)WinRTInterop.Callbacks.GetUserDefaultCulture();
+#else
+ return CultureInfo.GetUserDefaultCulture();
+#endif // ENABLE_WINRT
}
// PAL methods end here.
private static string GetLocaleInfoFromLCType(string localeName, uint lctype, bool useUserOveride)
{
- Contract.Assert(localeName != null, "[CultureData.GetLocaleInfoFromLCType] Expected localeName to be not be null");
+ Debug.Assert(localeName != null, "[CultureData.GetLocaleInfoFromLCType] Expected localeName to be not be null");
// Fix lctype if we don't want overrides
if (!useUserOveride)
@@ -557,5 +598,76 @@ namespace System.Globalization
return null;
}
+
+ private int LocaleNameToLCID(string cultureName)
+ {
+ return GetLocaleInfo(LocaleNumberData.LanguageId);
+ }
+
+ private static string LCIDToLocaleName(int culture)
+ {
+ throw new NotImplementedException();
+ }
+
+ 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)
+ {
+ throw new NotImplementedException();
+ }
+
+ private string GetConsoleFallbackName(string cultureName)
+ {
+ return GetLocaleInfo(cultureName, LocaleStringData.ConsoleFallbackName);
+ }
+
+ internal bool IsFramework
+ {
+ get { throw new NotImplementedException(); }
+ }
+
+ internal bool IsWin32Installed
+ {
+ get { throw new NotImplementedException(); }
+ }
+
+ internal bool IsReplacementCulture
+ {
+ get { throw new NotImplementedException(); }
+ }
+
}
}
diff --git a/src/mscorlib/corefx/System/Globalization/CultureData.cs b/src/mscorlib/corefx/System/Globalization/CultureData.cs
index eb71318fdb..c15a77cf45 100644
--- a/src/mscorlib/corefx/System/Globalization/CultureData.cs
+++ b/src/mscorlib/corefx/System/Globalization/CultureData.cs
@@ -2,25 +2,23 @@
// The .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;
using System.Collections.Generic;
+using System.Diagnostics;
using System.Text;
using System.Threading;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Diagnostics.Contracts;
namespace System.Globalization
{
#if INSIDE_CLR
using StringStringDictionary = Dictionary<string, string>;
- using StringCultureDataDictionary = Dictionary<String, CultureData>;
+ using StringCultureDataDictionary = Dictionary<string, CultureData>;
+ using LcidToCultureNameDictionary = Dictionary<int, string>;
using Lock = Object;
#else
using StringStringDictionary = LowLevelDictionary<string, string>;
using StringCultureDataDictionary = LowLevelDictionary<string, CultureData>;
+ using LcidToCultureNameDictionary = LowLevelDictionary<int, string>;
#endif
//
@@ -57,8 +55,6 @@ namespace System.Globalization
internal partial class CultureData
{
private const int undef = -1;
- private const int LOCALE_CUSTOM_UNSPECIFIED = 0x1000;
- private const int LOCALE_CUSTOM_DEFAULT = 0x0c00;
// Override flag
private String _sRealName; // Name you passed in (ie: en-US, en, or de-DE_phoneb)
@@ -74,9 +70,13 @@ namespace System.Globalization
// 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)
@@ -84,11 +84,12 @@ namespace System.Globalization
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
- private String[] _saNativeDigits; // (user can override) native characters for digits 0-9
// (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
@@ -108,6 +109,8 @@ namespace System.Globalization
// 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
@@ -145,6 +148,11 @@ namespace System.Globalization
// 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)
@@ -391,6 +399,42 @@ namespace System.Globalization
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);
+ }
+
+#pragma warning restore 618
+ return EnumCultures(types);
+ }
/////////////////////////////////////////////////////////////////////////
// Build our invariant information
@@ -422,20 +466,25 @@ namespace System.Globalization
// 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._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._saNativeDigits = new String[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" }; // native characters for digits 0-9
invariant._iDigits = 2; // number of fractional digits
invariant._iNegativeNumber = 1; // negative number format
invariant._waGrouping = new int[] { 3 }; // grouping of digits
@@ -454,6 +503,8 @@ namespace System.Globalization
// 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
@@ -487,7 +538,11 @@ namespace System.Globalization
// These are desktop only, not coreclr
- invariant._iLanguage = 0x007f; // locale ID (0409) - NO sort information
+ 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
// Remember it
s_Invariant = invariant;
}
@@ -605,6 +660,33 @@ namespace System.Globalization
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;
+
+ // Convert the lcid to a name, then use that
+ // Note that this'll 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;
+ }
+
////////////////////////////////////////////////////////////////////////
//
// All the accessors
@@ -622,7 +704,7 @@ namespace System.Globalization
{
get
{
- Contract.Assert(_sRealName != null, "[CultureData.CultureName] Expected _sRealName to be populated by already");
+ 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.
@@ -834,6 +916,17 @@ namespace System.Globalization
}
}
+ // The culture name to be used in CultureInfo.CreateSpecificCulture()
+ internal string SSPECIFICCULTURE
+ {
+ get
+ {
+ // This got populated during the culture initialization
+ Debug.Assert(_sSpecificCulture != null, "[CultureData.SSPECIFICCULTURE] Expected this.sSpecificCulture to be populated by culture data initialization already");
+ return _sSpecificCulture;
+ }
+ }
+
/////////////
// Language //
/////////////
@@ -845,12 +938,38 @@ namespace System.Globalization
{
if (_sISO639Language == null)
{
- _sISO639Language = GetLocaleInfo(LocaleStringData.Iso639LanguageName);
+ _sISO639Language = GetLocaleInfo(LocaleStringData.Iso639LanguageTwoLetterName);
}
return _sISO639Language;
}
}
+ // iso 639 language name, ie: eng
+ internal string SISO639LANGNAME2
+ {
+ get
+ {
+ if (_sISO639Language2 == null)
+ {
+ _sISO639Language2 = GetLocaleInfo(LocaleStringData.Iso639LanguageThreeLetterName);
+ }
+ return _sISO639Language2;
+ }
+ }
+
+ // abbreviated windows language name (ie: enu) (non-standard, avoid this)
+ internal string SABBREVLANGNAME
+ {
+ get
+ {
+ if (_sAbbrevLang == null)
+ {
+ _sAbbrevLang = GetThreeLetterWindowsLanguageName(_sRealName);
+ }
+ return _sAbbrevLang;
+ }
+ }
+
// Localized name for this language (Windows Only) ie: Inglis
// This is only valid for Windows 8 and higher neutrals:
internal String SLOCALIZEDLANGUAGE
@@ -922,6 +1041,17 @@ namespace System.Globalization
}
}
+ internal int IGEOID
+ {
+ get
+ {
+ if (_iGeoId == undef)
+ {
+ _iGeoId = GetGeoId(_sRealName);
+ }
+ return _iGeoId;
+ }
+ }
// localized name for the country
internal string SLOCALIZEDCOUNTRY
@@ -987,17 +1117,51 @@ namespace System.Globalization
}
}
- /////////////
- // Numbers //
- ////////////
-
- // internal String sPositiveSign ; // (user can override) positive sign
- // internal String sNegativeSign ; // (user can override) negative sign
- // internal String[] saNativeDigits ; // (user can override) native characters for digits 0-9
- // internal int iDigits ; // (user can override) number of fractional digits
- // internal int iNegativeNumber ; // (user can override) negative number format
+ // 3 letter ISO 3166 country code
+ internal String SISO3166CTRYNAME2
+ {
+ get
+ {
+ if (_sISO3166CountryName2 == null)
+ {
+ _sISO3166CountryName2 = GetLocaleInfo(LocaleStringData.Iso3166CountryName2);
+ }
+ return _sISO3166CountryName2;
+ }
+ }
+ internal int IINPUTLANGUAGEHANDLE
+ {
+ get
+ {
+ if (_iInputLanguageHandle == undef)
+ {
+ if (IsSupplementalCustomCulture)
+ {
+ _iInputLanguageHandle = 0x0409;
+ }
+ else
+ {
+ // Input Language is same as LCID for built-in cultures
+ _iInputLanguageHandle = this.ILANGUAGE;
+ }
+ }
+ return _iInputLanguageHandle;
+ }
+ }
+ // Console fallback name (ie: locale to use for console apps for unicode-only locales)
+ internal string SCONSOLEFALLBACKNAME
+ {
+ get
+ {
+ if (_sConsoleFallbackName == null)
+ {
+ _sConsoleFallbackName = GetConsoleFallbackName(_sRealName);
+ }
+ return _sConsoleFallbackName;
+ }
+ }
// (user can override) grouping of digits
internal int[] WAGROUPING
@@ -1144,6 +1308,32 @@ namespace System.Globalization
}
}
+ // English name for this currency (RegionInfo), eg: US Dollar
+ internal String SENGLISHCURRENCY
+ {
+ get
+ {
+ if (_sEnglishCurrency == null)
+ {
+ _sEnglishCurrency = GetLocaleInfo(LocaleStringData.CurrencyEnglishName);
+ }
+ return _sEnglishCurrency;
+ }
+ }
+
+ // Native name for this currency (RegionInfo), eg: Schweiz Frank
+ internal String SNATIVECURRENCY
+ {
+ get
+ {
+ if (_sNativeCurrency == null)
+ {
+ _sNativeCurrency = GetLocaleInfo(LocaleStringData.CurrencyNativeName);
+ }
+ return _sNativeCurrency;
+ }
+ }
+
// internal int iCurrencyDigits ; // (user can override) # local monetary fractional digits
// internal int iCurrency ; // (user can override) positive currency format
// internal int iNegativeCurrency ; // (user can override) negative currency format
@@ -1522,7 +1712,7 @@ namespace System.Globalization
// 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];
- Contract.Assert(_sWindowsName != null, "[CultureData.CalendarIds] Expected _sWindowsName to be populated by already");
+ 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.
@@ -1585,9 +1775,16 @@ namespace System.Globalization
}
}
+ // Native calendar names. index of optional calendar - 1, empty if no optional calendar at that number
+ internal string CalendarName(CalendarId calendarId)
+ {
+ // Get the calendar
+ return GetCalendar(calendarId).sNativeName;
+ }
+
internal CalendarData GetCalendar(CalendarId calendarId)
{
- Contract.Assert(calendarId > 0 && calendarId <= CalendarId.LAST_CALENDAR,
+ 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
@@ -1606,7 +1803,7 @@ namespace System.Globalization
// Make sure that calendar has data
if (calendarData == null)
{
- Contract.Assert(_sWindowsName != null, "[CultureData.GetCalendar] Expected _sWindowsName to be populated by already");
+ Debug.Assert(_sWindowsName != null, "[CultureData.GetCalendar] Expected _sWindowsName to be populated by already");
calendarData = new CalendarData(_sWindowsName, calendarId, this.UseUserOverride);
_calendars[calendarIndex] = calendarData;
}
@@ -1646,7 +1843,7 @@ namespace System.Globalization
{
if (_iReadingLayout == undef)
{
- Contract.Assert(_sRealName != null, "[CultureData.IsRightToLeft] Expected _sRealName to be populated by already");
+ Debug.Assert(_sRealName != null, "[CultureData.IsRightToLeft] Expected _sRealName to be populated by already");
_iReadingLayout = GetLocaleInfo(LocaleNumberData.ReadingLayout);
}
@@ -1667,8 +1864,8 @@ namespace System.Globalization
{
// 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.
- Contract.Assert(_sWindowsName != null, "[CultureData.STEXTINFO] Expected _sWindowsName to be populated by already");
- return (_sWindowsName);
+ Debug.Assert(_sRealName != null, "[CultureData.STEXTINFO] Expected _sRealName to be populated by already");
+ return (_sRealName);
}
}
@@ -1677,8 +1874,8 @@ namespace System.Globalization
{
get
{
- Contract.Assert(_sWindowsName != null, "[CultureData.SCOMPAREINFO] Expected _sWindowsName to be populated by already");
- return (_sWindowsName);
+ Debug.Assert(_sRealName != null, "[CultureData.SCOMPAREINFO] Expected _sRealName to be populated by already");
+ return (_sRealName);
}
}
@@ -1690,10 +1887,63 @@ namespace System.Globalization
}
}
+ internal int IDEFAULTANSICODEPAGE // default ansi code page ID (ACP)
+ {
+ get
+ {
+ if (_iDefaultAnsiCodePage == undef)
+ {
+ _iDefaultAnsiCodePage = GetAnsiCodePage(_sRealName);
+ }
+ return _iDefaultAnsiCodePage;
+ }
+ }
+
+ internal int IDEFAULTOEMCODEPAGE // default oem code page ID (OCP or OEM)
+ {
+ get
+ {
+ if (_iDefaultOemCodePage == undef)
+ {
+ _iDefaultOemCodePage = GetOemCodePage(_sRealName);
+ }
+ return _iDefaultOemCodePage;
+ }
+ }
+
+ internal int IDEFAULTMACCODEPAGE // default macintosh code page
+ {
+ get
+ {
+ if (_iDefaultMacCodePage == undef)
+ {
+ _iDefaultMacCodePage = GetMacCodePage(_sRealName);
+ }
+ return _iDefaultMacCodePage;
+ }
+ }
+
+ internal int IDEFAULTEBCDICCODEPAGE // default EBCDIC code page
+ {
+ get
+ {
+ if (_iDefaultEbcdicCodePage == undef)
+ {
+ _iDefaultEbcdicCodePage = GetEbcdicCodePage(_sRealName);
+ }
+ return _iDefaultEbcdicCodePage;
+ }
+ }
+
internal int ILANGUAGE
{
get
{
+ if (_iLanguage == 0)
+ {
+ Debug.Assert(_sRealName != null, "[CultureData.ILANGUAGE] Expected this.sRealName to be populated by COMNlsInfo::nativeInitCultureData already");
+ _iLanguage = LocaleNameToLCID(_sRealName);
+ }
return _iLanguage;
}
}
@@ -1734,21 +1984,21 @@ namespace System.Globalization
// All of our era names
internal String[] EraNames(CalendarId calendarId)
{
- Contract.Assert(calendarId > 0, "[CultureData.saEraNames] Expected Calendar.ID > 0");
+ Debug.Assert(calendarId > 0, "[CultureData.saEraNames] Expected Calendar.ID > 0");
return this.GetCalendar(calendarId).saEraNames;
}
internal String[] AbbrevEraNames(CalendarId calendarId)
{
- Contract.Assert(calendarId > 0, "[CultureData.saAbbrevEraNames] Expected Calendar.ID > 0");
+ Debug.Assert(calendarId > 0, "[CultureData.saAbbrevEraNames] Expected Calendar.ID > 0");
return this.GetCalendar(calendarId).saAbbrevEraNames;
}
internal String[] AbbreviatedEnglishEraNames(CalendarId calendarId)
{
- Contract.Assert(calendarId > 0, "[CultureData.saAbbrevEraNames] Expected Calendar.ID > 0");
+ Debug.Assert(calendarId > 0, "[CultureData.saAbbrevEraNames] Expected Calendar.ID > 0");
return this.GetCalendar(calendarId).saAbbrevEnglishEraNames;
}
@@ -1808,9 +2058,9 @@ namespace System.Globalization
////////////////////////////////////////////////////////////////////////////
private static String UnescapeNlsString(String str, int start, int end)
{
- Contract.Requires(str != null);
- Contract.Requires(start >= 0);
- Contract.Requires(end >= 0);
+ 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++)
@@ -1908,8 +2158,8 @@ namespace System.Globalization
private static int IndexOfTimePart(string format, int startIndex, string timeParts)
{
- Contract.Assert(startIndex >= 0, "startIndex cannot be negative");
- Contract.Assert(timeParts.IndexOfAny(new char[] { '\'', '\\' }) == -1, "timeParts cannot include quote characters");
+ 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)
{
@@ -1944,9 +2194,9 @@ namespace System.Globalization
return -1;
}
- private static bool IsCustomCultureId(int cultureId)
+ internal static bool IsCustomCultureId(int cultureId)
{
- return (cultureId == LOCALE_CUSTOM_DEFAULT || cultureId == LOCALE_CUSTOM_UNSPECIFIED);
+ return (cultureId == CultureInfo.LOCALE_CUSTOM_DEFAULT || cultureId == CultureInfo.LOCALE_CUSTOM_UNSPECIFIED);
}
internal void GetNFIValues(NumberFormatInfo nfi)
@@ -1954,7 +2204,6 @@ namespace System.Globalization
if (this.IsInvariantCulture)
{
// FUTURE: NumberFormatInfo already has default values for many of these fields. Can we not do this?
- // if we do need to do this, then why don't we set nfi.nativeDigits in this case?
nfi.positiveSign = _sPositiveSign;
nfi.negativeSign = _sNegativeSign;
@@ -1972,7 +2221,7 @@ namespace System.Globalization
}
else
{
- Contract.Assert(_sWindowsName != null, "[CultureData.GetNFIValues] Expected _sWindowsName to be populated by already");
+ 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);
@@ -1997,6 +2246,8 @@ namespace System.Globalization
{
nfi.nativeDigits[i] = new string(digits[i], 1);
}
+
+ nfi.digitSubstitution = GetDigitSubstitution(_sRealName);
}
//
@@ -2043,9 +2294,26 @@ namespace System.Globalization
// This is ONLY used for caching names and shouldn't be used for anything else
internal static string AnsiToLower(string testString)
{
+ int index = 0;
+
+ while (index<testString.Length && (testString[index]<'A' || testString[index]>'Z' ))
+ {
+ index++;
+ }
+ if (index >= testString.Length)
+ {
+ return testString; // we didn't really change the string
+ }
+
StringBuilder sb = new StringBuilder(testString.Length);
+ for (int i=0; i<index; i++)
+ {
+ sb.Append(testString[i]);
+ }
- for (int ich = 0; ich < testString.Length; ich++)
+ sb.Append((char) (testString[index] -'A' + 'a'));
+
+ for (int ich = index+1; ich < testString.Length; ich++)
{
char ch = testString[ich];
sb.Append(ch <= 'Z' && ch >= 'A' ? (char)(ch - 'A' + 'a') : ch);
@@ -2072,10 +2340,14 @@ namespace System.Globalization
EnglishLanguageName = 0x00001001,
/// <summary>native name of language, eg "Deutsch" (coresponds to LOCALE_SNATIVELANGUAGENAME)</summary>
NativeLanguageName = 0x00000004,
+ /// <summary>localized name of country, eg "Germany" in UI language (coresponds to LOCALE_SLOCALIZEDCOUNTRYNAME)</summary>
+ LocalizedCountryName = 0x00000006,
/// <summary>English name of country, eg "Germany" (coresponds to LOCALE_SENGLISHCOUNTRYNAME)</summary>
EnglishCountryName = 0x00001002,
/// <summary>native name of country, eg "Deutschland" (coresponds to LOCALE_SNATIVECOUNTRYNAME)</summary>
NativeCountryName = 0x00000008,
+ /// <summary>abbreviated language name (coresponds to LOCALE_SABBREVLANGNAME)</summary>
+ AbbreviatedWindowsLanguageName = 0x00000003,
/// <summary>list item separator (coresponds to LOCALE_SLIST)</summary>
ListSeparator = 0x0000000C,
/// <summary>decimal separator (coresponds to LOCALE_SDECIMAL)</summary>
@@ -2086,6 +2358,10 @@ namespace System.Globalization
Digits = 0x00000013,
/// <summary>local monetary symbol (coresponds to LOCALE_SCURRENCY)</summary>
MonetarySymbol = 0x00000014,
+ /// <summary>English currency name (coresponds to LOCALE_SENGCURRNAME)</summary>
+ CurrencyEnglishName = 0x00001007,
+ /// <summary>Native currency name (coresponds to LOCALE_SNATIVECURRNAME)</summary>
+ CurrencyNativeName = 0x00001008,
/// <summary>uintl monetary symbol (coresponds to LOCALE_SINTLSYMBOL)</summary>
Iso4217MonetarySymbol = 0x00000015,
/// <summary>monetary decimal separator (coresponds to LOCALE_SMONDECIMALSEP)</summary>
@@ -2101,9 +2377,15 @@ namespace System.Globalization
/// <summary>negative sign (coresponds to LOCALE_SNEGATIVESIGN)</summary>
NegativeSign = 0x00000051,
/// <summary>ISO abbreviated language name (coresponds to LOCALE_SISO639LANGNAME)</summary>
+ Iso639LanguageTwoLetterName = 0x00000059,
+ /// <summary>ISO abbreviated country name (coresponds to LOCALE_SISO639LANGNAME2)</summary>
+ Iso639LanguageThreeLetterName = 0x00000067,
+ /// <summary>ISO abbreviated language name (coresponds to LOCALE_SISO639LANGNAME)</summary>
Iso639LanguageName = 0x00000059,
/// <summary>ISO abbreviated country name (coresponds to LOCALE_SISO3166CTRYNAME)</summary>
Iso3166CountryName = 0x0000005A,
+ /// <summary>3 letter ISO country code (coresponds to LOCALE_SISO3166CTRYNAME2)</summary>
+ Iso3166CountryName2 = 0x00000068, // 3 character ISO country name
/// <summary>Not a Number (coresponds to LOCALE_SNAN)</summary>
NaNSymbol = 0x00000069,
/// <summary>+ Infinity (coresponds to LOCALE_SPOSINFINITY)</summary>
@@ -2112,6 +2394,8 @@ namespace System.Globalization
NegativeInfinitySymbol = 0x0000006b,
/// <summary>Fallback name for resources (coresponds to LOCALE_SPARENT)</summary>
ParentName = 0x0000006d,
+ /// <summary>Fallback name for within the console (coresponds to LOCALE_SCONSOLEFALLBACKNAME)</summary>
+ ConsoleFallbackName = 0x0000006e,
/// <summary>Returns the percent symbol (coresponds to LOCALE_SPERCENT)</summary>
PercentSymbol = 0x00000076,
/// <summary>Returns the permille (U+2030) symbol (coresponds to LOCALE_SPERMILLE)</summary>
@@ -2138,6 +2422,10 @@ namespace System.Globalization
{
/// <summary>language id (coresponds to LOCALE_ILANGUAGE)</summary>
LanguageId = 0x00000001,
+ /// <summary>geographical location id, (coresponds to LOCALE_IGEOID)</summary>
+ GeoId = 0x00000008,
+ /// <summary>0 = context, 1 = none, 2 = national (coresponds to LOCALE_IDIGITSUBSTITUTION)</summary>
+ DigitSubstitution = 0x00001014,
/// <summary>0 = metric, 1 = US (coresponds to LOCALE_IMEASURE)</summary>
MeasurementSystem = 0x0000000D,
/// <summary>number of fractional digits (coresponds to LOCALE_IDIGITS)</summary>
@@ -2168,7 +2456,15 @@ namespace System.Globalization
/// <summary>Returns 0-11 for the negative percent format (coresponds to LOCALE_INEGATIVEPERCENT)</summary>
NegativePercentFormat = 0x00000074,
/// <summary>Returns 0-3 for the positive percent format (coresponds to LOCALE_IPOSITIVEPERCENT)</summary>
- PositivePercentFormat = 0x00000075
+ PositivePercentFormat = 0x00000075,
+ /// <summary>default ansi code page (coresponds to LOCALE_IDEFAULTCODEPAGE)</summary>
+ OemCodePage = 0x0000000B,
+ /// <summary>default ansi code page (coresponds to LOCALE_IDEFAULTANSICODEPAGE)</summary>
+ AnsiCodePage = 0x00001004,
+ /// <summary>default mac code page (coresponds to LOCALE_IDEFAULTMACCODEPAGE)</summary>
+ MacCodePage = 0x00001011,
+ /// <summary>default ebcdic code page (coresponds to LOCALE_IDEFAULTEBCDICCODEPAGE)</summary>
+ EbcdicCodePage = 0x00001012,
}
}
}
diff --git a/src/mscorlib/corefx/System/Globalization/CultureInfo.Windows.cs b/src/mscorlib/corefx/System/Globalization/CultureInfo.Windows.cs
index 16c8a06e08..c019eb2ceb 100644
--- a/src/mscorlib/corefx/System/Globalization/CultureInfo.Windows.cs
+++ b/src/mscorlib/corefx/System/Globalization/CultureInfo.Windows.cs
@@ -2,7 +2,9 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+#if ENABLE_WINRT
using Internal.Runtime.Augments;
+#endif
namespace System.Globalization
{
@@ -16,16 +18,18 @@ namespace System.Globalization
/// </remarks>
private static CultureInfo GetUserDefaultCultureCacheOverride()
{
+#if ENABLE_WINRT
WinRTInteropCallbacks callbacks = WinRTInterop.UnsafeCallbacks;
if (callbacks != null && callbacks.IsAppxModel())
{
return (CultureInfo)callbacks.GetUserDefaultCulture();
}
+#endif
return null;
}
- private static CultureInfo GetUserDefaultCulture()
+ internal static CultureInfo GetUserDefaultCulture()
{
const uint LOCALE_SNAME = 0x0000005c;
const string LOCALE_NAME_USER_DEFAULT = null;
diff --git a/src/mscorlib/corefx/System/Globalization/CultureInfo.cs b/src/mscorlib/corefx/System/Globalization/CultureInfo.cs
index f2b3742ab4..da084d17f9 100644
--- a/src/mscorlib/corefx/System/Globalization/CultureInfo.cs
+++ b/src/mscorlib/corefx/System/Globalization/CultureInfo.cs
@@ -1,4 +1,4 @@
-// Licensed to the .NET Foundation under one or more agreements.
+// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
@@ -26,15 +26,10 @@
//
////////////////////////////////////////////////////////////////////////////
-using System;
-using System.Collections;
using System.Collections.Generic;
+using System.Diagnostics;
using System.Diagnostics.Contracts;
-using System.Runtime;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
using System.Runtime.Serialization;
-using System.Security;
using System.Threading;
namespace System.Globalization
@@ -42,9 +37,12 @@ namespace System.Globalization
#if INSIDE_CLR
using StringCultureInfoDictionary = Dictionary<string, CultureInfo>;
+ using StringLcidDictionary = Dictionary<int, CultureInfo>;
+
using Lock = Object;
#else
using StringCultureInfoDictionary = LowLevelDictionary<string, CultureInfo>;
+ using StringLcidDictionary = LowLevelDictionary<int, CultureInfo>;
#endif
[Serializable]
@@ -79,6 +77,9 @@ namespace System.Globalization
[NonSerialized]
internal bool m_isInherited;
+ [NonSerialized]
+ private CultureInfo m_consoleFallbackCulture;
+
// Names are confusing. Here are 3 names we have:
//
// new CultureInfo() m_name m_nonSortName m_sortName
@@ -106,7 +107,6 @@ namespace System.Globalization
[NonSerialized]
private string m_sortName;
-
//--------------------------------------------------------------------//
//
// Static data members
@@ -139,11 +139,21 @@ namespace System.Globalization
private static readonly Lock m_lock = new Lock();
private static volatile StringCultureInfoDictionary s_NameCachedCultures;
+ private static volatile StringLcidDictionary s_LcidCachedCultures;
//The parent culture.
[NonSerialized]
private CultureInfo m_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;
+
static AsyncLocal<CultureInfo> s_asyncLocalCurrentCulture;
static AsyncLocal<CultureInfo> s_asyncLocalCurrentUICulture;
@@ -189,17 +199,55 @@ namespace System.Globalization
}
- internal CultureInfo(String name, bool useUserOverride)
+ public CultureInfo(String name, bool useUserOverride)
{
if (name == null)
{
- throw new ArgumentNullException("name",
+ throw new ArgumentNullException(nameof(name),
SR.ArgumentNull_String);
}
InitializeFromName(name, useUserOverride);
}
+ 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);
+ }
+ Contract.EndContractBlock();
+
+ InitializeFromCultureId(culture, useUserOverride);
+ }
+
+ private void InitializeFromCultureId(int culture, bool useUserOverride)
+ {
+ 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.
+ m_cultureData = CultureData.GetCultureData(culture, useUserOverride);
+ break;
+ }
+ m_isInherited = (this.GetType() != typeof(System.Globalization.CultureInfo));
+ m_name = m_cultureData.CultureName;
+ }
+
private void InitializeFromName(string name, bool useUserOverride)
{
// Get our data providing record
@@ -207,13 +255,38 @@ namespace System.Globalization
if (this.m_cultureData == null)
{
- throw new CultureNotFoundException("name", name, SR.Argument_CultureNotSupported);
+ throw new CultureNotFoundException(nameof(name), name, SR.Argument_CultureNotSupported);
}
this.m_name = this.m_cultureData.CultureName;
this.m_isInherited = (this.GetType() != typeof(System.Globalization.CultureInfo));
}
+ // 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*.
+ internal CultureInfo(String cultureName, String textAndCompareCultureName)
+ {
+ if (cultureName == null)
+ {
+ throw new ArgumentNullException(nameof(cultureName),SR.ArgumentNull_String);
+ }
+ Contract.EndContractBlock();
+
+ m_cultureData = CultureData.GetCultureData(cultureName, false);
+ if (m_cultureData == null)
+ throw new CultureNotFoundException(nameof(cultureName), cultureName, SR.Argument_CultureNotSupported);
+
+ m_name = m_cultureData.CultureName;
+
+ CultureInfo altCulture = GetCultureInfo(textAndCompareCultureName);
+ compareInfo = altCulture.CompareInfo;
+ textInfo = altCulture.TextInfo;
+ }
+
// 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)
//
@@ -239,6 +312,66 @@ namespace System.Globalization
return ci;
}
+ //
+ // 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
+ //
+ public static CultureInfo CreateSpecificCulture(String name)
+ {
+ Contract.Ensures(Contract.Result<CultureInfo>() != null);
+
+ 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.
+
+ int idx;
+
+ culture = null;
+ for (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.m_cultureData.SSPECIFICCULTURE));
+ }
+
// //
// // Return a specific culture. A tad irrelevent now since we always return valid data
// // for neutral locales.
@@ -296,7 +429,7 @@ namespace System.Globalization
[OnDeserialized]
private void OnDeserialized(StreamingContext ctx)
{
- Contract.Assert(m_name != null, "[CultureInfo.OnDeserialized] m_name != null");
+ Debug.Assert(m_name != null, "[CultureInfo.OnDeserialized] m_name != null");
InitializeFromName(m_name, m_useUserOverride);
}
@@ -348,7 +481,7 @@ namespace System.Globalization
Init();
}
- Contract.Assert(s_userDefaultCulture != null);
+ Debug.Assert(s_userDefaultCulture != null);
return s_userDefaultCulture;
}
@@ -356,7 +489,7 @@ namespace System.Globalization
{
if (value == null)
{
- throw new ArgumentNullException("value");
+ throw new ArgumentNullException(nameof(value));
}
if (s_asyncLocalCurrentCulture == null)
@@ -396,7 +529,7 @@ namespace System.Globalization
Init();
}
- Contract.Assert(s_userDefaultCulture != null);
+ Debug.Assert(s_userDefaultCulture != null);
return s_userDefaultCulture;
}
@@ -404,7 +537,7 @@ namespace System.Globalization
{
if (value == null)
{
- throw new ArgumentNullException("value");
+ throw new ArgumentNullException(nameof(value));
}
CultureInfo.VerifyCultureName(value, true);
@@ -419,6 +552,20 @@ namespace System.Globalization
}
}
+ public static CultureInfo InstalledUICulture
+ {
+ get
+ {
+ Contract.Ensures(Contract.Result<CultureInfo>() != null);
+ if (s_userDefaultCulture == null)
+ {
+ Init();
+ }
+ Debug.Assert(s_userDefaultCulture != null, "[CultureInfo.InstalledUICulture] s_userDefaultCulture != null");
+ return s_userDefaultCulture;
+ }
+ }
+
public static CultureInfo DefaultThreadCurrentCulture
{
get { return s_DefaultThreadCurrentCulture; }
@@ -513,6 +660,34 @@ namespace System.Globalization
}
}
+ public virtual int LCID
+ {
+ get
+ {
+ return (this.m_cultureData.ILANGUAGE);
+ }
+ }
+
+ public virtual int KeyboardLayoutId
+ {
+ get
+ {
+ return m_cultureData.IINPUTLANGUAGEHANDLE;
+ }
+ }
+
+ public static CultureInfo[] GetCultures(CultureTypes types)
+ {
+ Contract.Ensures(Contract.Result<CultureInfo[]>() != null);
+ // 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));
+ }
+
////////////////////////////////////////////////////////////////////////
//
// Name
@@ -552,6 +727,24 @@ namespace System.Globalization
}
}
+ public string IetfLanguageTag
+ {
+ get
+ {
+ Contract.Ensures(Contract.Result<string>() != null);
+
+ // special case the compatibility cultures
+ switch (this.Name)
+ {
+ case "zh-CHT":
+ return "zh-Hant";
+ case "zh-CHS":
+ return "zh-Hans";
+ default:
+ return this.Name;
+ }
+ }
+ }
////////////////////////////////////////////////////////////////////////
//
@@ -567,7 +760,7 @@ namespace System.Globalization
get
{
Contract.Ensures(Contract.Result<String>() != null);
- Contract.Assert(m_name != null, "[CultureInfo.DisplayName] Always expect m_name to be set");
+ Debug.Assert(m_name != null, "[CultureInfo.DisplayName] Always expect m_name to be set");
return m_cultureData.SLOCALIZEDDISPLAYNAME;
}
@@ -619,6 +812,32 @@ namespace System.Globalization
}
}
+ // ie: eng
+ public virtual String ThreeLetterISOLanguageName
+ {
+ get
+ {
+ Contract.Ensures(Contract.Result<String>() != null);
+ return m_cultureData.SISO639LANGNAME2;
+ }
+ }
+
+ ////////////////////////////////////////////////////////////////////////
+ //
+ // ThreeLetterWindowsLanguageName
+ //
+ // Returns the 3 letter windows language name for the current instance. eg: "ENU"
+ // The ISO names are much preferred
+ //
+ ////////////////////////////////////////////////////////////////////////
+ public virtual String ThreeLetterWindowsLanguageName
+ {
+ get
+ {
+ Contract.Ensures(Contract.Result<String>() != null);
+ return m_cultureData.SABBREVLANGNAME;
+ }
+ }
////////////////////////////////////////////////////////////////////////
//
@@ -767,6 +986,31 @@ namespace System.Globalization
}
}
+ public CultureTypes CultureTypes
+ {
+ get
+ {
+ CultureTypes types = 0;
+
+ if (m_cultureData.IsNeutralCulture)
+ types |= CultureTypes.NeutralCultures;
+ else
+ types |= CultureTypes.SpecificCultures;
+
+ types |= m_cultureData.IsWin32Installed ? CultureTypes.InstalledWin32Cultures : 0;
+
+// Disable warning 618: System.Globalization.CultureTypes.FrameworkCultures' is obsolete
+#pragma warning disable 618
+ types |= m_cultureData.IsFramework ? CultureTypes.FrameworkCultures : 0;
+
+#pragma warning restore 618
+ types |= m_cultureData.IsSupplementalCustomCulture ? CultureTypes.UserCustomCulture : 0;
+ types |= m_cultureData.IsReplacementCulture ? CultureTypes.ReplacementCultures | CultureTypes.UserCustomCulture : 0;
+
+ return types;
+ }
+ }
+
public virtual NumberFormatInfo NumberFormat
{
get
@@ -775,7 +1019,7 @@ namespace System.Globalization
{
NumberFormatInfo temp = new NumberFormatInfo(this.m_cultureData);
temp.isReadOnly = m_isReadOnly;
- numInfo = temp;
+ Interlocked.CompareExchange(ref numInfo, temp, null);
}
return (numInfo);
}
@@ -783,7 +1027,7 @@ namespace System.Globalization
{
if (value == null)
{
- throw new ArgumentNullException("value", SR.ArgumentNull_Obj);
+ throw new ArgumentNullException(nameof(value), SR.ArgumentNull_Obj);
}
VerifyWritable();
numInfo = value;
@@ -807,8 +1051,7 @@ namespace System.Globalization
// Change the calendar of DTFI to the specified calendar of this CultureInfo.
DateTimeFormatInfo temp = new DateTimeFormatInfo(this.m_cultureData, this.Calendar);
temp._isReadOnly = m_isReadOnly;
- System.Threading.Interlocked.MemoryBarrier();
- dateTimeInfo = temp;
+ Interlocked.CompareExchange(ref dateTimeInfo, temp, null);
}
return (dateTimeInfo);
}
@@ -817,13 +1060,28 @@ namespace System.Globalization
{
if (value == null)
{
- throw new ArgumentNullException("value", SR.ArgumentNull_Obj);
+ throw new ArgumentNullException(nameof(value), SR.ArgumentNull_Obj);
}
VerifyWritable();
dateTimeInfo = value;
}
}
+ public void ClearCachedData()
+ {
+ s_userDefaultCulture = null;
+
+ RegionInfo.s_currentRegionInfo = null;
+ #pragma warning disable 0618 // disable the obsolete warning
+ TimeZone.ResetTimeZone();
+ #pragma warning restore 0618
+ TimeZoneInfo.ClearCachedData();
+ s_LcidCachedCultures = null;
+ s_NameCachedCultures = null;
+
+ CultureData.ClearCachedData();
+ }
+
/*=================================GetCalendarInstance==========================
**Action: Map a Win32 CALID to an instance of supported calendar.
**Returns: An instance of calendar.
@@ -845,7 +1103,7 @@ namespace System.Globalization
//calendars unless they're required.
internal static Calendar GetCalendarInstanceRare(CalendarId calType)
{
- Contract.Assert(calType != CalendarId.GREGORIAN, "calType!=CalendarId.GREGORIAN");
+ Debug.Assert(calType != CalendarId.GREGORIAN, "calType!=CalendarId.GREGORIAN");
switch (calType)
{
@@ -889,7 +1147,7 @@ namespace System.Globalization
{
if (calendar == null)
{
- Contract.Assert(this.m_cultureData.CalendarIds.Length > 0, "this.m_cultureData.CalendarIds.Length > 0");
+ Debug.Assert(this.m_cultureData.CalendarIds.Length > 0, "this.m_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 = this.m_cultureData.DefaultCalendar;
@@ -929,13 +1187,26 @@ namespace System.Globalization
}
}
-
- private bool UseUserOverride
+ public bool UseUserOverride
{
get
{
- return (this.m_cultureData.UseUserOverride);
+ return m_cultureData.UseUserOverride;
+ }
+ }
+
+ public CultureInfo GetConsoleFallbackUICulture()
+ {
+ Contract.Ensures(Contract.Result<CultureInfo>() != null);
+
+ CultureInfo temp = m_consoleFallbackCulture;
+ if (temp == null)
+ {
+ temp = CreateSpecificCulture(m_cultureData.SCONSOLEFALLBACKNAME);
+ temp.m_isReadOnly = true;
+ m_consoleFallbackCulture = temp;
}
+ return (temp);
}
public virtual Object Clone()
@@ -979,7 +1250,7 @@ namespace System.Globalization
{
if (ci == null)
{
- throw new ArgumentNullException("ci");
+ throw new ArgumentNullException(nameof(ci));
}
Contract.Ensures(Contract.Result<CultureInfo>() != null);
Contract.EndContractBlock();
@@ -1054,26 +1325,25 @@ namespace System.Globalization
get { return Name == CultureInfo.InvariantCulture.Name; }
}
- // Helper function both both overloads of GetCachedReadOnlyCulture.
- internal static CultureInfo GetCultureInfoHelper(string name)
+ // Helper function both both overloads of GetCachedReadOnlyCulture. If lcid is 0, we use the name.
+ // If lcid is -1, use the altName and create one of those special SQL cultures.
+ internal static CultureInfo GetCultureInfoHelper(int lcid, string name, string altName)
{
- // There is a race condition in this code with the side effect that the second thread's value
- // clobbers the first in the dictionary. This is an acceptable race since the CultureInfo objects
- // are content equal (but not reference equal). Since we make no guarantees there, this race is
- // acceptable.
-
// retval is our return value.
CultureInfo retval;
- if (name == null)
- {
- return null;
- }
-
// Temporary hashtable for the names.
StringCultureInfoDictionary tempNameHT = s_NameCachedCultures;
- name = CultureData.AnsiToLower(name);
+ if (name != null)
+ {
+ name = CultureData.AnsiToLower(name);
+ }
+
+ if (altName != null)
+ {
+ altName = CultureData.AnsiToLower(altName);
+ }
// We expect the same result for both hashtables, but will test individually for added safety.
if (tempNameHT == null)
@@ -1082,20 +1352,66 @@ namespace System.Globalization
}
else
{
- bool ret;
- lock (m_lock)
+ // If we are called by name, check if the object exists in the hashtable. If so, return it.
+ if (lcid == -1 || lcid == 0)
{
- ret = tempNameHT.TryGetValue(name, out retval);
+ bool ret;
+ lock (m_lock)
+ {
+ ret = tempNameHT.TryGetValue(lcid == 0 ? name : name + '\xfffd' + altName, out retval);
+ }
+
+ if (ret && retval != null)
+ {
+ return retval;
+ }
}
+ }
- if (ret && retval != null)
+ // Next, the Lcid table.
+ StringLcidDictionary tempLcidHT = s_LcidCachedCultures;
+
+ if (tempLcidHT == null)
+ {
+ // Case insensitive is not an issue here, save the constructor call.
+ tempLcidHT = new StringLcidDictionary();
+ }
+ else
+ {
+ // If we were called by Lcid, check if the object exists in the table. If so, return it.
+ if (lcid > 0)
{
- return retval;
+ bool ret;
+ lock (m_lock)
+ {
+ ret = tempLcidHT.TryGetValue(lcid, out retval);
+ }
+ if (ret && retval != null)
+ {
+ return retval;
+ }
}
}
+
+ // We now have two temporary hashtables and the desired object was not found.
+ // We'll construct it. We catch any exceptions from the constructor call and return null.
try
{
- retval = new CultureInfo(name, false);
+ switch (lcid)
+ {
+ case -1:
+ // call the private constructor
+ retval = new CultureInfo(name, altName);
+ break;
+
+ case 0:
+ retval = new CultureInfo(name, false);
+ break;
+
+ default:
+ retval = new CultureInfo(lcid, false);
+ break;
+ }
}
catch (ArgumentException)
{
@@ -1105,14 +1421,42 @@ namespace System.Globalization
// Set it to read-only
retval.m_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)
- string newName = CultureData.AnsiToLower(retval.m_name);
+ if (lcid == -1)
+ {
+ lock (m_lock)
+ {
+ // This new culture will be added only to the name hash table.
+ tempNameHT[name + '\xfffd' + altName] = retval;
+ }
+ // when lcid == -1 then TextInfo object is already get created and we need to set it as read only.
+ retval.TextInfo.SetReadOnlyState(true);
+ }
+ else if (lcid == 0)
+ {
+ // 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)
+ string newName = CultureData.AnsiToLower(retval.m_name);
+
+ // We add this new culture info object to both tables.
+ lock (m_lock)
+ {
+ tempNameHT[newName] = retval;
+ }
+ }
+ else
+ {
+ lock (m_lock)
+ {
+ tempLcidHT[lcid] = retval;
+ }
+ }
- // We add this new culture info object to both tables.
- lock (m_lock)
+ // Copy the two hashtables to the corresponding member variables. This will potentially overwrite
+ // new tables simultaneously created by a new thread, but maximizes thread safety.
+ if (-1 != lcid)
{
- tempNameHT[newName] = retval;
+ // Only when we modify the lcid hash table, is there a need to overwrite.
+ s_LcidCachedCultures = tempLcidHT;
}
s_NameCachedCultures = tempNameHT;
@@ -1122,23 +1466,93 @@ namespace System.Globalization
}
// Gets a cached copy of the specified culture from an internal hashtable (or creates it
+ // if not found). (LCID version)... use named version
+ public static CultureInfo GetCultureInfo(int culture)
+ {
+ // Must check for -1 now since the helper function uses the value to signal
+ // the altCulture code path for SQL Server.
+ // Also check for zero as this would fail trying to add as a key to the hash.
+ if (culture <= 0)
+ {
+ throw new ArgumentOutOfRangeException(nameof(culture), SR.ArgumentOutOfRange_NeedPosNum);
+ }
+ Contract.Ensures(Contract.Result<CultureInfo>() != null);
+ Contract.EndContractBlock();
+ CultureInfo retval = GetCultureInfoHelper(culture, null, null);
+ if (null == retval)
+ {
+ throw new CultureNotFoundException(nameof(culture), culture, SR.Argument_CultureNotSupported);
+ }
+ return retval;
+ }
+
+ // Gets a cached copy of the specified culture from an internal hashtable (or creates it
// if not found). (Named version)
- internal static CultureInfo GetCultureInfo(string name)
+ public static CultureInfo GetCultureInfo(string name)
{
// Make sure we have a valid, non-zero length string as name
if (name == null)
{
- throw new ArgumentNullException("name");
+ throw new ArgumentNullException(nameof(name));
}
- CultureInfo retval = GetCultureInfoHelper(name);
+ CultureInfo retval = GetCultureInfoHelper(0, name, null);
if (retval == null)
{
throw new CultureNotFoundException(
- "name", name, SR.Argument_CultureNotSupported);
+ nameof(name), name, SR.Argument_CultureNotSupported);
+ }
+ return retval;
+ }
+
+ // Gets a cached copy of the specified culture from an internal hashtable (or creates it
+ // if not found).
+ public static CultureInfo GetCultureInfo(string name, string altName)
+ {
+ // Make sure we have a valid, non-zero length string as name
+ if (name == null)
+ {
+ throw new ArgumentNullException(nameof(name));
+ }
+
+ if (altName == null)
+ {
+ throw new ArgumentNullException(nameof(altName));
+ }
+
+ Contract.Ensures(Contract.Result<CultureInfo>() != null);
+ Contract.EndContractBlock();
+
+ CultureInfo retval = GetCultureInfoHelper(-1, name, altName);
+ if (retval == null)
+ {
+ throw new CultureNotFoundException("name or altName",
+ SR.Format(SR.Argument_OneOfCulturesNotSupported, name, altName));
}
return retval;
}
+
+ // This function is deprecated, we don't like it
+ public static CultureInfo GetCultureInfoByIetfLanguageTag(string name)
+ {
+ Contract.Ensures(Contract.Result<CultureInfo>() != null);
+
+ // 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/src/mscorlib/corefx/System/Globalization/CultureNotFoundException.cs b/src/mscorlib/corefx/System/Globalization/CultureNotFoundException.cs
index 740063e4d3..64782d28c0 100644
--- a/src/mscorlib/corefx/System/Globalization/CultureNotFoundException.cs
+++ b/src/mscorlib/corefx/System/Globalization/CultureNotFoundException.cs
@@ -13,6 +13,7 @@ namespace System.Globalization
public partial class CultureNotFoundException : ArgumentException, ISerializable
{
private string _invalidCultureName; // unrecognized culture name
+ private int? _invalidCultureId; // unrecognized culture Lcid
public CultureNotFoundException()
: base(DefaultMessage)
@@ -46,8 +47,22 @@ namespace System.Globalization
_invalidCultureName = invalidCultureName;
}
- protected CultureNotFoundException(SerializationInfo info, StreamingContext context) : base(info, context)
+ 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));
}
@@ -56,13 +71,19 @@ namespace System.Globalization
{
if (info == null)
{
- throw new ArgumentNullException("info");
+ throw new ArgumentNullException(nameof(info));
}
base.GetObjectData(info, context);
+ info.AddValue("InvalidCultureId", _invalidCultureId, typeof(int?));
info.AddValue("InvalidCultureName", _invalidCultureName, typeof(string));
}
+ public virtual Nullable<int> InvalidCultureId
+ {
+ get { return _invalidCultureId; }
+ }
+
public virtual string InvalidCultureName
{
get { return _invalidCultureName; }
@@ -80,7 +101,9 @@ namespace System.Globalization
{
get
{
- return InvalidCultureName;
+ return InvalidCultureId != null ?
+ String.Format(CultureInfo.InvariantCulture, "{0} (0x{0:x4})", (int)InvalidCultureId) :
+ InvalidCultureName;
}
}
@@ -89,12 +112,14 @@ namespace System.Globalization
get
{
String s = base.Message;
- if (
- _invalidCultureName != null)
+ if (_invalidCultureId != null || _invalidCultureName != null)
{
String valueMessage = SR.Format(SR.Argument_CultureInvalidIdentifier, FormatedInvalidCultureId);
if (s == null)
+ {
return valueMessage;
+ }
+
return s + Environment.NewLine + valueMessage;
}
return s;
diff --git a/src/mscorlib/corefx/System/Globalization/CultureTypes.cs b/src/mscorlib/corefx/System/Globalization/CultureTypes.cs
new file mode 100644
index 0000000000..80b588aabb
--- /dev/null
+++ b/src/mscorlib/corefx/System/Globalization/CultureTypes.cs
@@ -0,0 +1,28 @@
+// Licensed to the .NET Foundation under one or more 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
+{
+ [Serializable]
+ [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/src/mscorlib/corefx/System/Globalization/DateTimeFormatInfo.cs b/src/mscorlib/corefx/System/Globalization/DateTimeFormatInfo.cs
index da746ada88..216fc603d0 100644
--- a/src/mscorlib/corefx/System/Globalization/DateTimeFormatInfo.cs
+++ b/src/mscorlib/corefx/System/Globalization/DateTimeFormatInfo.cs
@@ -2,15 +2,10 @@
// The .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;
using System.Collections.Generic;
+using System.Diagnostics;
using System.Diagnostics.Contracts;
-using System.Runtime.InteropServices;
using System.Runtime.Serialization;
-using System.Security;
-using System.Text;
-using System.Threading;
namespace System.Globalization
{
@@ -55,8 +50,7 @@ namespace System.Globalization
[Serializable]
- [System.Runtime.InteropServices.ComVisible(true)]
- public sealed partial class DateTimeFormatInfo : IFormatProvider, ICloneable
+ public sealed class DateTimeFormatInfo : IFormatProvider, ICloneable
{
// cache for the invariant culture.
// invariantInfo is constant irrespective of your current culture.
@@ -228,7 +222,7 @@ namespace System.Globalization
{
// Get the abbreviated day names for our current calendar
this.abbreviatedDayNames = _cultureData.AbbreviatedDayNames(Calendar.ID);
- Contract.Assert(this.abbreviatedDayNames.Length == 7, "[DateTimeFormatInfo.GetAbbreviatedDayOfWeekNames] Expected 7 day names in a week");
+ Debug.Assert(this.abbreviatedDayNames.Length == 7, "[DateTimeFormatInfo.GetAbbreviatedDayOfWeekNames] Expected 7 day names in a week");
}
return (this.abbreviatedDayNames);
}
@@ -252,7 +246,7 @@ namespace System.Globalization
{
// Get the super short day names for our current calendar
this.m_superShortDayNames = _cultureData.SuperShortDayNames(Calendar.ID);
- Contract.Assert(this.m_superShortDayNames.Length == 7, "[DateTimeFormatInfo.internalGetSuperShortDayNames] Expected 7 day names in a week");
+ Debug.Assert(this.m_superShortDayNames.Length == 7, "[DateTimeFormatInfo.internalGetSuperShortDayNames] Expected 7 day names in a week");
}
return (this.m_superShortDayNames);
}
@@ -269,7 +263,7 @@ namespace System.Globalization
{
// Get the day names for our current calendar
this.dayNames = _cultureData.DayNames(Calendar.ID);
- Contract.Assert(this.dayNames.Length == 7, "[DateTimeFormatInfo.GetDayOfWeekNames] Expected 7 day names in a week");
+ Debug.Assert(this.dayNames.Length == 7, "[DateTimeFormatInfo.GetDayOfWeekNames] Expected 7 day names in a week");
}
return (this.dayNames);
}
@@ -286,7 +280,7 @@ namespace System.Globalization
{
// Get the month names for our current calendar
this.abbreviatedMonthNames = _cultureData.AbbreviatedMonthNames(Calendar.ID);
- Contract.Assert(this.abbreviatedMonthNames.Length == 12 || this.abbreviatedMonthNames.Length == 13,
+ Debug.Assert(this.abbreviatedMonthNames.Length == 12 || this.abbreviatedMonthNames.Length == 13,
"[DateTimeFormatInfo.GetAbbreviatedMonthNames] Expected 12 or 13 month names in a year");
}
return (this.abbreviatedMonthNames);
@@ -305,7 +299,7 @@ namespace System.Globalization
{
// Get the month names for our current calendar
this.monthNames = _cultureData.MonthNames(Calendar.ID);
- Contract.Assert(this.monthNames.Length == 12 || this.monthNames.Length == 13,
+ Debug.Assert(this.monthNames.Length == 12 || this.monthNames.Length == 13,
"[DateTimeFormatInfo.GetMonthNames] Expected 12 or 13 month names in a year");
}
@@ -324,8 +318,8 @@ namespace System.Globalization
internal DateTimeFormatInfo(CultureData cultureData, Calendar cal)
{
- Contract.Requires(cultureData != null);
- Contract.Requires(cal != null);
+ Debug.Assert(cultureData != null);
+ Debug.Assert(cal != null);
// Remember our culture
_cultureData = cultureData;
@@ -335,8 +329,8 @@ namespace System.Globalization
private void InitializeOverridableProperties(CultureData cultureData, CalendarId calendarId)
{
- Contract.Requires(cultureData != null);
- Contract.Assert(calendarId != CalendarId.UNINITIALIZED_VALUE, "[DateTimeFormatInfo.Populate] Expected initalized calendarId");
+ Debug.Assert(cultureData != null);
+ Debug.Assert(calendarId != CalendarId.UNINITIALIZED_VALUE, "[DateTimeFormatInfo.Populate] Expected initalized calendarId");
if (this.firstDayOfWeek == -1) { this.firstDayOfWeek = cultureData.IFIRSTDAYOFWEEK; }
if (this.calendarWeekRule == -1) { this.calendarWeekRule = cultureData.IFIRSTWEEKOFYEAR; }
@@ -347,19 +341,19 @@ namespace System.Globalization
if (this.dateSeparator == null) { this.dateSeparator = cultureData.DateSeparator(calendarId); }
this.allLongTimePatterns = _cultureData.LongTimes;
- Contract.Assert(this.allLongTimePatterns.Length > 0, "[DateTimeFormatInfo.Populate] Expected some long time patterns");
+ Debug.Assert(this.allLongTimePatterns.Length > 0, "[DateTimeFormatInfo.Populate] Expected some long time patterns");
this.allShortTimePatterns = _cultureData.ShortTimes;
- Contract.Assert(this.allShortTimePatterns.Length > 0, "[DateTimeFormatInfo.Populate] Expected some short time patterns");
+ Debug.Assert(this.allShortTimePatterns.Length > 0, "[DateTimeFormatInfo.Populate] Expected some short time patterns");
this.allLongDatePatterns = cultureData.LongDates(calendarId);
- Contract.Assert(this.allLongDatePatterns.Length > 0, "[DateTimeFormatInfo.Populate] Expected some long date patterns");
+ Debug.Assert(this.allLongDatePatterns.Length > 0, "[DateTimeFormatInfo.Populate] Expected some long date patterns");
this.allShortDatePatterns = cultureData.ShortDates(calendarId);
- Contract.Assert(this.allShortDatePatterns.Length > 0, "[DateTimeFormatInfo.Populate] Expected some short date patterns");
+ Debug.Assert(this.allShortDatePatterns.Length > 0, "[DateTimeFormatInfo.Populate] Expected some short date patterns");
this.allYearMonthPatterns = cultureData.YearMonths(calendarId);
- Contract.Assert(this.allYearMonthPatterns.Length > 0, "[DateTimeFormatInfo.Populate] Expected some year month patterns");
+ Debug.Assert(this.allYearMonthPatterns.Length > 0, "[DateTimeFormatInfo.Populate] Expected some year month patterns");
}
[OptionalField(VersionAdded = 1)]
@@ -527,7 +521,7 @@ namespace System.Globalization
{
this.amDesignator = _cultureData.SAM1159;
}
- Contract.Assert(this.amDesignator != null, "DateTimeFormatInfo.AMDesignator, amDesignator != null");
+ Debug.Assert(this.amDesignator != null, "DateTimeFormatInfo.AMDesignator, amDesignator != null");
return (this.amDesignator);
}
@@ -537,7 +531,7 @@ namespace System.Globalization
throw new InvalidOperationException(SR.InvalidOperation_ReadOnly);
if (value == null)
{
- throw new ArgumentNullException("value",
+ throw new ArgumentNullException(nameof(value),
SR.ArgumentNull_String);
}
Contract.EndContractBlock();
@@ -553,7 +547,7 @@ namespace System.Globalization
{
Contract.Ensures(Contract.Result<Calendar>() != null);
- Contract.Assert(this.calendar != null, "DateTimeFormatInfo.Calendar: calendar != null");
+ Debug.Assert(this.calendar != null, "DateTimeFormatInfo.Calendar: calendar != null");
return (this.calendar);
}
@@ -563,7 +557,7 @@ namespace System.Globalization
throw new InvalidOperationException(SR.InvalidOperation_ReadOnly);
if (value == null)
{
- throw new ArgumentNullException("value", SR.ArgumentNull_Obj);
+ throw new ArgumentNullException(nameof(value), SR.ArgumentNull_Obj);
}
Contract.EndContractBlock();
if (value == calendar)
@@ -641,7 +635,7 @@ namespace System.Globalization
}
// The assigned calendar is not a valid calendar for this culture, throw
- throw new ArgumentOutOfRangeException("value", SR.Argument_InvalidCalendar);
+ throw new ArgumentOutOfRangeException(nameof(value), SR.Argument_InvalidCalendar);
}
}
@@ -670,7 +664,7 @@ namespace System.Globalization
{
if (eraName == null)
{
- throw new ArgumentNullException("eraName",
+ throw new ArgumentNullException(nameof(eraName),
SR.ArgumentNull_String);
}
Contract.EndContractBlock();
@@ -759,7 +753,7 @@ namespace System.Globalization
{
return (m_eraNames[era]);
}
- throw new ArgumentOutOfRangeException("era", SR.ArgumentOutOfRange_InvalidEraValue);
+ throw new ArgumentOutOfRangeException(nameof(era), SR.ArgumentOutOfRange_InvalidEraValue);
}
internal String[] AbbreviatedEraNames
@@ -791,7 +785,7 @@ namespace System.Globalization
{
return (m_abbrevEraNames[era]);
}
- throw new ArgumentOutOfRangeException("era", SR.ArgumentOutOfRange_InvalidEraValue);
+ throw new ArgumentOutOfRangeException(nameof(era), SR.ArgumentOutOfRange_InvalidEraValue);
}
internal String[] AbbreviatedEnglishEraNames
@@ -800,34 +794,41 @@ namespace System.Globalization
{
if (this.m_abbrevEnglishEraNames == null)
{
- Contract.Assert(Calendar.ID > 0, "[DateTimeFormatInfo.AbbreviatedEnglishEraNames] Expected Calendar.ID > 0");
+ Debug.Assert(Calendar.ID > 0, "[DateTimeFormatInfo.AbbreviatedEnglishEraNames] Expected Calendar.ID > 0");
this.m_abbrevEnglishEraNames = _cultureData.AbbreviatedEnglishEraNames(Calendar.ID);
}
return (this.m_abbrevEnglishEraNames);
}
}
-
// Note that cultureData derives this from the short date format (unless someone's set this previously)
// Note that this property is quite undesirable.
- internal String DateSeparator
+ public string DateSeparator
{
get
{
- if (this.dateSeparator == null)
+ if (dateSeparator == null)
{
- this.dateSeparator = _cultureData.DateSeparator(Calendar.ID);
+ dateSeparator = _cultureData.DateSeparator(Calendar.ID);
}
- Contract.Assert(this.dateSeparator != null, "DateTimeFormatInfo.DateSeparator, dateSeparator != null");
- return (this.dateSeparator);
+ Debug.Assert(this.dateSeparator != null, "DateTimeFormatInfo.DateSeparator, dateSeparator != null");
+ return dateSeparator;
}
set
{
- throw null;
+ if (IsReadOnly)
+ throw new InvalidOperationException(SR.InvalidOperation_ReadOnly);
+
+ if (value == null)
+ {
+ throw new ArgumentNullException(nameof(value), SR.ArgumentNull_String);
+ }
+ Contract.EndContractBlock();
+ ClearTokenHashTable();
+ dateSeparator = value;
}
}
-
public DayOfWeek FirstDayOfWeek
{
get
@@ -836,7 +837,7 @@ namespace System.Globalization
{
this.firstDayOfWeek = _cultureData.IFIRSTDAYOFWEEK;
}
- Contract.Assert(this.firstDayOfWeek != -1, "DateTimeFormatInfo.FirstDayOfWeek, firstDayOfWeek != -1");
+ Debug.Assert(this.firstDayOfWeek != -1, "DateTimeFormatInfo.FirstDayOfWeek, firstDayOfWeek != -1");
return ((DayOfWeek)this.firstDayOfWeek);
}
@@ -852,7 +853,7 @@ namespace System.Globalization
else
{
throw new ArgumentOutOfRangeException(
- "value", SR.Format(SR.ArgumentOutOfRange_Range,
+ nameof(value), SR.Format(SR.ArgumentOutOfRange_Range,
DayOfWeek.Sunday, DayOfWeek.Saturday));
}
}
@@ -866,7 +867,7 @@ namespace System.Globalization
{
this.calendarWeekRule = _cultureData.IFIRSTWEEKOFYEAR;
}
- Contract.Assert(this.calendarWeekRule != -1, "DateTimeFormatInfo.CalendarWeekRule, calendarWeekRule != -1");
+ Debug.Assert(this.calendarWeekRule != -1, "DateTimeFormatInfo.CalendarWeekRule, calendarWeekRule != -1");
return ((CalendarWeekRule)this.calendarWeekRule);
}
@@ -881,7 +882,7 @@ namespace System.Globalization
else
{
throw new ArgumentOutOfRangeException(
- "value", SR.Format(SR.ArgumentOutOfRange_Range,
+ nameof(value), SR.Format(SR.ArgumentOutOfRange_Range,
CalendarWeekRule.FirstDay, CalendarWeekRule.FirstFourDayWeek));
}
}
@@ -904,7 +905,7 @@ namespace System.Globalization
throw new InvalidOperationException(SR.InvalidOperation_ReadOnly);
if (value == null)
{
- throw new ArgumentNullException("value",
+ throw new ArgumentNullException(nameof(value),
SR.ArgumentNull_String);
}
Contract.EndContractBlock();
@@ -938,7 +939,7 @@ namespace System.Globalization
throw new InvalidOperationException(SR.InvalidOperation_ReadOnly);
if (value == null)
{
- throw new ArgumentNullException("value",
+ throw new ArgumentNullException(nameof(value),
SR.ArgumentNull_String);
}
Contract.EndContractBlock();
@@ -979,7 +980,7 @@ namespace System.Globalization
throw new InvalidOperationException(SR.InvalidOperation_ReadOnly);
if (value == null)
{
- throw new ArgumentNullException("value",
+ throw new ArgumentNullException(nameof(value),
SR.ArgumentNull_String);
}
Contract.EndContractBlock();
@@ -1005,10 +1006,10 @@ namespace System.Globalization
{
if (this.monthDayPattern == null)
{
- Contract.Assert(Calendar.ID > 0, "[DateTimeFormatInfo.MonthDayPattern] Expected calID > 0");
+ Debug.Assert(Calendar.ID > 0, "[DateTimeFormatInfo.MonthDayPattern] Expected calID > 0");
this.monthDayPattern = _cultureData.MonthDay(Calendar.ID);
}
- Contract.Assert(this.monthDayPattern != null, "DateTimeFormatInfo.MonthDayPattern, monthDayPattern != null");
+ Debug.Assert(this.monthDayPattern != null, "DateTimeFormatInfo.MonthDayPattern, monthDayPattern != null");
return (this.monthDayPattern);
}
@@ -1018,7 +1019,7 @@ namespace System.Globalization
throw new InvalidOperationException(SR.InvalidOperation_ReadOnly);
if (value == null)
{
- throw new ArgumentNullException("value",
+ throw new ArgumentNullException(nameof(value),
SR.ArgumentNull_String);
}
Contract.EndContractBlock();
@@ -1037,7 +1038,7 @@ namespace System.Globalization
{
this.pmDesignator = _cultureData.SPM2359;
}
- Contract.Assert(this.pmDesignator != null, "DateTimeFormatInfo.PMDesignator, pmDesignator != null");
+ Debug.Assert(this.pmDesignator != null, "DateTimeFormatInfo.PMDesignator, pmDesignator != null");
return (this.pmDesignator);
}
@@ -1047,7 +1048,7 @@ namespace System.Globalization
throw new InvalidOperationException(SR.InvalidOperation_ReadOnly);
if (value == null)
{
- throw new ArgumentNullException("value",
+ throw new ArgumentNullException(nameof(value),
SR.ArgumentNull_String);
}
Contract.EndContractBlock();
@@ -1090,7 +1091,7 @@ namespace System.Globalization
if (IsReadOnly)
throw new InvalidOperationException(SR.InvalidOperation_ReadOnly);
if (value == null)
- throw new ArgumentNullException("value",
+ throw new ArgumentNullException(nameof(value),
SR.ArgumentNull_String);
Contract.EndContractBlock();
@@ -1132,7 +1133,7 @@ namespace System.Globalization
throw new InvalidOperationException(SR.InvalidOperation_ReadOnly);
if (value == null)
{
- throw new ArgumentNullException("value",
+ throw new ArgumentNullException(nameof(value),
SR.ArgumentNull_String);
}
Contract.EndContractBlock();
@@ -1270,7 +1271,7 @@ namespace System.Globalization
// Note that cultureData derives this from the long time format (unless someone's set this previously)
// Note that this property is quite undesirable.
- internal String TimeSeparator
+ public string TimeSeparator
{
get
{
@@ -1278,17 +1279,27 @@ namespace System.Globalization
{
timeSeparator = _cultureData.TimeSeparator;
}
- Contract.Assert(this.timeSeparator != null, "DateTimeFormatInfo.TimeSeparator, timeSeparator != null");
+ Debug.Assert(this.timeSeparator != null, "DateTimeFormatInfo.TimeSeparator, timeSeparator != null");
return (timeSeparator);
}
set
{
- throw null;
+ if (IsReadOnly)
+ throw new InvalidOperationException(SR.InvalidOperation_ReadOnly);
+
+ if (value == null)
+ {
+ throw new ArgumentNullException(nameof(value), SR.ArgumentNull_String);
+ }
+
+ Contract.EndContractBlock();
+ ClearTokenHashTable();
+
+ timeSeparator = value;
}
}
-
public String UniversalSortableDateTimePattern
{
get
@@ -1321,7 +1332,7 @@ namespace System.Globalization
throw new InvalidOperationException(SR.InvalidOperation_ReadOnly);
if (value == null)
{
- throw new ArgumentNullException("value",
+ throw new ArgumentNullException(nameof(value),
SR.ArgumentNull_String);
}
Contract.EndContractBlock();
@@ -1339,8 +1350,8 @@ namespace System.Globalization
//
private static void CheckNullValue(String[] values, int length)
{
- Contract.Requires(values != null, "value != null");
- Contract.Requires(values.Length >= length);
+ Debug.Assert(values != null, "value != null");
+ Debug.Assert(values.Length >= length);
for (int i = 0; i < length; i++)
{
if (values[i] == null)
@@ -1365,12 +1376,12 @@ namespace System.Globalization
throw new InvalidOperationException(SR.InvalidOperation_ReadOnly);
if (value == null)
{
- throw new ArgumentNullException("value",
+ throw new ArgumentNullException(nameof(value),
SR.ArgumentNull_Array);
}
if (value.Length != 7)
{
- throw new ArgumentException(SR.Format(SR.Argument_InvalidArrayLength, 7), "value");
+ throw new ArgumentException(SR.Format(SR.Argument_InvalidArrayLength, 7), nameof(value));
}
Contract.EndContractBlock();
CheckNullValue(value, value.Length);
@@ -1381,7 +1392,6 @@ namespace System.Globalization
}
// Returns the string array of the one-letter day of week names.
- [System.Runtime.InteropServices.ComVisible(false)]
public String[] ShortestDayNames
{
get
@@ -1395,12 +1405,12 @@ namespace System.Globalization
throw new InvalidOperationException(SR.InvalidOperation_ReadOnly);
if (value == null)
{
- throw new ArgumentNullException("value",
+ throw new ArgumentNullException(nameof(value),
SR.ArgumentNull_Array);
}
if (value.Length != 7)
{
- throw new ArgumentException(SR.Format(SR.Argument_InvalidArrayLength, 7), "value");
+ throw new ArgumentException(SR.Format(SR.Argument_InvalidArrayLength, 7), nameof(value));
}
Contract.EndContractBlock();
CheckNullValue(value, value.Length);
@@ -1422,12 +1432,12 @@ namespace System.Globalization
throw new InvalidOperationException(SR.InvalidOperation_ReadOnly);
if (value == null)
{
- throw new ArgumentNullException("value",
+ throw new ArgumentNullException(nameof(value),
SR.ArgumentNull_Array);
}
if (value.Length != 7)
{
- throw new ArgumentException(SR.Format(SR.Argument_InvalidArrayLength, 7), "value");
+ throw new ArgumentException(SR.Format(SR.Argument_InvalidArrayLength, 7), nameof(value));
}
Contract.EndContractBlock();
CheckNullValue(value, value.Length);
@@ -1451,12 +1461,12 @@ namespace System.Globalization
throw new InvalidOperationException(SR.InvalidOperation_ReadOnly);
if (value == null)
{
- throw new ArgumentNullException("value",
+ throw new ArgumentNullException(nameof(value),
SR.ArgumentNull_Array);
}
if (value.Length != 13)
{
- throw new ArgumentException(SR.Format(SR.Argument_InvalidArrayLength, 13), "value");
+ throw new ArgumentException(SR.Format(SR.Argument_InvalidArrayLength, 13), nameof(value));
}
Contract.EndContractBlock();
CheckNullValue(value, value.Length - 1);
@@ -1479,12 +1489,12 @@ namespace System.Globalization
throw new InvalidOperationException(SR.InvalidOperation_ReadOnly);
if (value == null)
{
- throw new ArgumentNullException("value",
+ throw new ArgumentNullException(nameof(value),
SR.ArgumentNull_Array);
}
if (value.Length != 13)
{
- throw new ArgumentException(SR.Format(SR.Argument_InvalidArrayLength, 13), "value");
+ throw new ArgumentException(SR.Format(SR.Argument_InvalidArrayLength, 13), nameof(value));
}
Contract.EndContractBlock();
CheckNullValue(value, value.Length - 1);
@@ -1550,7 +1560,7 @@ namespace System.Globalization
if ((month < 1) || (month > monthNamesArray.Length))
{
throw new ArgumentOutOfRangeException(
- "month", SR.Format(SR.ArgumentOutOfRange_Range,
+ nameof(month), SR.Format(SR.ArgumentOutOfRange_Range,
1, monthNamesArray.Length));
}
return (monthNamesArray[month - 1]);
@@ -1571,7 +1581,7 @@ namespace System.Globalization
if (this.m_genitiveAbbreviatedMonthNames == null)
{
this.m_genitiveAbbreviatedMonthNames = _cultureData.AbbreviatedGenitiveMonthNames(this.Calendar.ID);
- Contract.Assert(this.m_genitiveAbbreviatedMonthNames.Length == 13,
+ Debug.Assert(this.m_genitiveAbbreviatedMonthNames.Length == 13,
"[DateTimeFormatInfo.GetGenitiveMonthNames] Expected 13 abbreviated genitive month names in a year");
}
return (this.m_genitiveAbbreviatedMonthNames);
@@ -1580,7 +1590,7 @@ namespace System.Globalization
if (this.genitiveMonthNames == null)
{
this.genitiveMonthNames = _cultureData.GenitiveMonthNames(this.Calendar.ID);
- Contract.Assert(this.genitiveMonthNames.Length == 13,
+ Debug.Assert(this.genitiveMonthNames.Length == 13,
"[DateTimeFormatInfo.GetGenitiveMonthNames] Expected 13 genitive month names in a year");
}
return (this.genitiveMonthNames);
@@ -1597,9 +1607,9 @@ namespace System.Globalization
{
if (this.leapYearMonthNames == null)
{
- Contract.Assert(Calendar.ID > 0, "[DateTimeFormatInfo.internalGetLeapYearMonthNames] Expected Calendar.ID > 0");
+ Debug.Assert(Calendar.ID > 0, "[DateTimeFormatInfo.internalGetLeapYearMonthNames] Expected Calendar.ID > 0");
this.leapYearMonthNames = _cultureData.LeapYearMonthNames(Calendar.ID);
- Contract.Assert(this.leapYearMonthNames.Length == 13,
+ Debug.Assert(this.leapYearMonthNames.Length == 13,
"[DateTimeFormatInfo.internalGetLeapYearMonthNames] Expepcted 13 leap year month names");
}
return (leapYearMonthNames);
@@ -1611,7 +1621,7 @@ namespace System.Globalization
if ((int)dayofweek < 0 || (int)dayofweek > 6)
{
throw new ArgumentOutOfRangeException(
- "dayofweek", SR.Format(SR.ArgumentOutOfRange_Range,
+ nameof(dayofweek), SR.Format(SR.ArgumentOutOfRange_Range,
DayOfWeek.Sunday, DayOfWeek.Saturday));
}
Contract.EndContractBlock();
@@ -1622,11 +1632,28 @@ namespace System.Globalization
return (internalGetAbbreviatedDayOfWeekNames()[(int)dayofweek]);
}
+ // Returns the super short day of week names for the specified day of week.
+ public string GetShortestDayName(DayOfWeek dayOfWeek)
+ {
+ if ((int)dayOfWeek < 0 || (int)dayOfWeek > 6)
+ {
+ throw new ArgumentOutOfRangeException(
+ nameof(dayOfWeek), SR.Format(SR.ArgumentOutOfRange_Range,
+ DayOfWeek.Sunday, DayOfWeek.Saturday));
+ }
+ Contract.EndContractBlock();
+ //
+ // 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]);
+ }
+
// Get all possible combination of inputs
private static String[] GetCombinedPatterns(String[] patterns1, String[] patterns2, String connectString)
{
- Contract.Requires(patterns1 != null);
- Contract.Requires(patterns2 != null);
+ Debug.Assert(patterns1 != null);
+ Debug.Assert(patterns2 != null);
// Get array size
String[] result = new String[patterns1.Length * patterns2.Length];
@@ -1646,9 +1673,22 @@ namespace System.Globalization
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();
+ }
- // auto-generated
- internal String[] GetAllDateTimePatterns(char format)
+ public string[] GetAllDateTimePatterns(char format)
{
Contract.Ensures(Contract.Result<String[]>() != null);
String[] result = null;
@@ -1703,7 +1743,7 @@ namespace System.Globalization
result = this.AllYearMonthPatterns;
break;
default:
- throw new ArgumentException(SR.Format_BadFormatSpecifier, "format");
+ throw new ArgumentException(SR.Format_BadFormatSpecifier, nameof(format));
}
return (result);
}
@@ -1714,7 +1754,7 @@ namespace System.Globalization
if ((int)dayofweek < 0 || (int)dayofweek > 6)
{
throw new ArgumentOutOfRangeException(
- "dayofweek", SR.Format(SR.ArgumentOutOfRange_Range,
+ nameof(dayofweek), SR.Format(SR.ArgumentOutOfRange_Range,
DayOfWeek.Sunday, DayOfWeek.Saturday));
}
Contract.EndContractBlock();
@@ -1730,7 +1770,7 @@ namespace System.Globalization
if (month < 1 || month > 13)
{
throw new ArgumentOutOfRangeException(
- "month", SR.Format(SR.ArgumentOutOfRange_Range,
+ nameof(month), SR.Format(SR.ArgumentOutOfRange_Range,
1, 13));
}
Contract.EndContractBlock();
@@ -1744,7 +1784,7 @@ namespace System.Globalization
if (month < 1 || month > 13)
{
throw new ArgumentOutOfRangeException(
- "month", SR.Format(SR.ArgumentOutOfRange_Range,
+ nameof(month), SR.Format(SR.ArgumentOutOfRange_Range,
1, 13));
}
Contract.EndContractBlock();
@@ -1761,9 +1801,9 @@ namespace System.Globalization
// The resulting [] can get returned to the calling app, so clone it.
private static string[] GetMergedPatterns(string[] patterns, string defaultPattern)
{
- Contract.Assert(patterns != null && patterns.Length > 0,
+ Debug.Assert(patterns != null && patterns.Length > 0,
"[DateTimeFormatInfo.GetMergedPatterns]Expected array of at least one pattern");
- Contract.Assert(defaultPattern != null,
+ 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
@@ -1864,9 +1904,9 @@ namespace System.Globalization
{
if (this.allYearMonthPatterns == null)
{
- Contract.Assert(Calendar.ID > 0, "[DateTimeFormatInfo.UnclonedYearMonthPatterns] Expected Calendar.ID > 0");
+ Debug.Assert(Calendar.ID > 0, "[DateTimeFormatInfo.UnclonedYearMonthPatterns] Expected Calendar.ID > 0");
this.allYearMonthPatterns = _cultureData.YearMonths(this.Calendar.ID);
- Contract.Assert(this.allYearMonthPatterns.Length > 0,
+ Debug.Assert(this.allYearMonthPatterns.Length > 0,
"[DateTimeFormatInfo.UnclonedYearMonthPatterns] Expected some year month patterns");
}
@@ -1883,9 +1923,9 @@ namespace System.Globalization
{
if (allShortDatePatterns == null)
{
- Contract.Assert(Calendar.ID > 0, "[DateTimeFormatInfo.UnclonedShortDatePatterns] Expected Calendar.ID > 0");
+ Debug.Assert(Calendar.ID > 0, "[DateTimeFormatInfo.UnclonedShortDatePatterns] Expected Calendar.ID > 0");
this.allShortDatePatterns = _cultureData.ShortDates(this.Calendar.ID);
- Contract.Assert(this.allShortDatePatterns.Length > 0,
+ Debug.Assert(this.allShortDatePatterns.Length > 0,
"[DateTimeFormatInfo.UnclonedShortDatePatterns] Expected some short date patterns");
}
@@ -1901,9 +1941,9 @@ namespace System.Globalization
{
if (allLongDatePatterns == null)
{
- Contract.Assert(Calendar.ID > 0, "[DateTimeFormatInfo.UnclonedLongDatePatterns] Expected Calendar.ID > 0");
+ Debug.Assert(Calendar.ID > 0, "[DateTimeFormatInfo.UnclonedLongDatePatterns] Expected Calendar.ID > 0");
this.allLongDatePatterns = _cultureData.LongDates(this.Calendar.ID);
- Contract.Assert(this.allLongDatePatterns.Length > 0,
+ Debug.Assert(this.allLongDatePatterns.Length > 0,
"[DateTimeFormatInfo.UnclonedLongDatePatterns] Expected some long date patterns");
}
@@ -1920,7 +1960,7 @@ namespace System.Globalization
if (this.allShortTimePatterns == null)
{
this.allShortTimePatterns = _cultureData.ShortTimes;
- Contract.Assert(this.allShortTimePatterns.Length > 0,
+ Debug.Assert(this.allShortTimePatterns.Length > 0,
"[DateTimeFormatInfo.UnclonedShortTimePatterns] Expected some short time patterns");
}
@@ -1937,7 +1977,7 @@ namespace System.Globalization
if (this.allLongTimePatterns == null)
{
this.allLongTimePatterns = _cultureData.LongTimes;
- Contract.Assert(this.allLongTimePatterns.Length > 0,
+ Debug.Assert(this.allLongTimePatterns.Length > 0,
"[DateTimeFormatInfo.UnclonedLongTimePatterns] Expected some long time patterns");
}
@@ -1949,7 +1989,7 @@ namespace System.Globalization
{
if (dtfi == null)
{
- throw new ArgumentNullException("dtfi",
+ throw new ArgumentNullException(nameof(dtfi),
SR.ArgumentNull_Obj);
}
Contract.EndContractBlock();
@@ -1973,7 +2013,99 @@ namespace System.Globalization
}
}
- [System.Runtime.InteropServices.ComVisible(false)]
+ // 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.
+ public string NativeCalendarName
+ {
+ get
+ {
+ return _cultureData.CalendarName(Calendar.ID);
+ }
+ }
+
+ //
+ // 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.
+ //
+ public void SetAllDateTimePatterns(String[] patterns, char format)
+ {
+ if (IsReadOnly)
+ throw new InvalidOperationException(SR.InvalidOperation_ReadOnly);
+
+ if (patterns == null)
+ {
+ throw new ArgumentNullException(nameof(patterns), SR.ArgumentNull_Array);
+ }
+
+ if (patterns.Length == 0)
+ {
+ throw new ArgumentException(SR.Arg_ArrayZeroError, nameof(patterns));
+ }
+
+ Contract.EndContractBlock();
+
+ for (int i=0; i<patterns.Length; i++)
+ {<