Merge pull request #656 from LogosBible/collection_lock
[mono.git] / mcs / class / corlib / System / Console.cs
index 71963cdc8c3b4c9500020f3bc386337b3c0a4057..08f8a4c1da1bfe92ecd879883d42b60b86374e1e 100644 (file)
@@ -7,7 +7,7 @@
 //
 // (C) Ximian, Inc.  http://www.ximian.com
 // (C) 2004,2005 Novell, Inc. (http://www.novell.com)
-//
+// Copyright 2013 Xamarin Inc. (http://www.xamarin.com)
 
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
@@ -39,7 +39,7 @@ using System.Text;
 
 namespace System
 {
-       public static class Console
+       public static partial class Console
        {
 #if !NET_2_1
                private class WindowsConsole
@@ -94,12 +94,6 @@ namespace System
                private static TextWriter stderr;
                private static TextReader stdin;
 
-#if NET_4_5
-               static TextWriter console_stdout;
-               static TextWriter console_stderr;
-               static TextReader console_stdin;
-#endif
-
                static Console ()
                {
 #if NET_2_1
@@ -158,17 +152,19 @@ namespace System
                                stdin = new CStreamReader (OpenStandardInput (0), inputEncoding);
                        } else {
 #endif
-#if FULL_AOT_RUNTIME
-                               Type nslogwriter = Type.GetType ("MonoTouch.Foundation.NSLogWriter, monotouch, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null");
-                               stdout = (TextWriter) Activator.CreateInstance (nslogwriter);
+// FULL_AOT_RUNTIME is used (instead of MONOTOUCH) since we only want this code when running on 
+// iOS (simulator or devices) and *not* when running tools (e.g. btouch #12179) that needs to use 
+// the mscorlib.dll shipped with Xamarin.iOS
+#if MONOTOUCH && FULL_AOT_RUNTIME
+                               stdout = new NSLogWriter ();
 #else
                                stdout = new UnexceptionalStreamWriter (OpenStandardOutput (0), outputEncoding);
                                ((StreamWriter)stdout).AutoFlush = true;
 #endif
                                stdout = TextWriter.Synchronized (stdout, true);
 
-#if FULL_AOT_RUNTIME
-                               stderr = (TextWriter) Activator.CreateInstance (nslogwriter);
+#if MONOTOUCH && FULL_AOT_RUNTIME
+                               stderr = new NSLogWriter ();
 #else
                                stderr = new UnexceptionalStreamWriter (OpenStandardError (0), outputEncoding); 
                                ((StreamWriter)stderr).AutoFlush = true;
@@ -181,12 +177,6 @@ namespace System
                        }
 #endif
 
-#if NET_4_5
-                       console_stderr = stderr;
-                       console_stdout = stdout;
-                       console_stdin = stdin;
-#endif
-
 #if MONODROID
                        if (LogcatTextWriter.IsRunningOnAndroid ()) {
                                stdout = TextWriter.Synchronized (new LogcatTextWriter ("mono-stdout", stdout));
@@ -219,10 +209,6 @@ namespace System
 
                private static Stream Open (IntPtr handle, FileAccess access, int bufferSize)
                {
-#if MOONLIGHT
-                       if (SecurityManager.SecurityEnabled && !Debugger.IsAttached && Environment.GetEnvironmentVariable ("MOONLIGHT_ENABLE_CONSOLE") == null)
-                               return new NullStream ();
-#endif
                        try {
                                return new FileStream (handle, access, false, bufferSize, false, bufferSize == 0);
                        } catch (IOException) {
@@ -678,19 +664,19 @@ namespace System
 #if NET_4_5
                public static bool IsErrorRedirected {
                        get {
-                               return stderr != console_stderr || ConsoleDriver.IsErrorRedirected;
+                               return ConsoleDriver.IsErrorRedirected;
                        }
                }
 
                public static bool IsOutputRedirected {
                        get {
-                               return stdout != console_stdout || ConsoleDriver.IsOutputRedirected;
+                               return ConsoleDriver.IsOutputRedirected;
                        }
                }
 
                public static bool IsInputRedirected {
                        get {
-                               return stdin != console_stdin || ConsoleDriver.IsInputRedirected;
+                               return ConsoleDriver.IsInputRedirected;
                        }
                }
 #endif