From e6f0cc2c1ecc490e5b8cd73bc80709f5a6e7a635 Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Sat, 9 Jul 2016 17:48:16 -0400 Subject: [PATCH 1/2] Add EnvironmentAugments to corert --- .../Runtime/Augments/EnvironmentAugments.cs | 21 +++++++++++++++++++ .../src/System.Private.CoreLib.csproj | 1 + 2 files changed, 22 insertions(+) create mode 100644 src/System.Private.CoreLib/src/Internal/Runtime/Augments/EnvironmentAugments.cs diff --git a/src/System.Private.CoreLib/src/Internal/Runtime/Augments/EnvironmentAugments.cs b/src/System.Private.CoreLib/src/Internal/Runtime/Augments/EnvironmentAugments.cs new file mode 100644 index 00000000000..de915e984f2 --- /dev/null +++ b/src/System.Private.CoreLib/src/Internal/Runtime/Augments/EnvironmentAugments.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; + +namespace Internal.Runtime.Augments +{ + /// For internal use only. Exposes runtime functionality to the Environments implementation in corefx. + public static class EnvironmentAugments + { + public static int CurrentManagedThreadId => Environment.CurrentManagedThreadId; + public static void Exit(int exitCode) => Environment.Exit(exitCode); + public static int ExitCode { get { return 0; } set { throw new PlatformNotSupportedException(); } } + public static void FailFast(string message, Exception error) => Environment.FailFast(message, error); + public static string[] GetCommandLineArgs() => Environment.GetCommandLineArgs(); + public static bool HasShutdownStarted => Environment.HasShutdownStarted; + public static string StackTrace => Environment.StackTrace; + public static int TickCount => Environment.TickCount; + } +} diff --git a/src/System.Private.CoreLib/src/System.Private.CoreLib.csproj b/src/System.Private.CoreLib/src/System.Private.CoreLib.csproj index cd1cabc5b53..6b6efcd53df 100644 --- a/src/System.Private.CoreLib/src/System.Private.CoreLib.csproj +++ b/src/System.Private.CoreLib/src/System.Private.CoreLib.csproj @@ -86,6 +86,7 @@ + From ff31b9b1c0648ab31becd2ce29cfb31f6238dfc5 Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Sun, 10 Jul 2016 11:21:45 -0400 Subject: [PATCH 2/2] Remove #if CORERT around GetCommandLineArgs And avoid null ref if GetCommandLineArgs is called without SetCommandLineArgs having been called. --- src/System.Private.CoreLib/src/System/Environment.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/System.Private.CoreLib/src/System/Environment.cs b/src/System.Private.CoreLib/src/System/Environment.cs index 0af58e76b27..e2c8b2c87c2 100644 --- a/src/System.Private.CoreLib/src/System/Environment.cs +++ b/src/System.Private.CoreLib/src/System/Environment.cs @@ -105,7 +105,6 @@ public static String NewLine } } -#if CORERT private static string[] s_commandLineArgs; internal static void SetCommandLineArgs(string[] args) @@ -115,9 +114,8 @@ internal static void SetCommandLineArgs(string[] args) public static string[] GetCommandLineArgs() { - return (string[])s_commandLineArgs.Clone(); + return (string[])s_commandLineArgs?.Clone(); } -#endif public static String StackTrace {