Home
Reading
Searching
Subscribe
Sponsors
Statistics
Posting
Contact
Spam
Lists
Links
About
Hosting
Filtering
Features Download
Marketing
Archives
FAQ
Blog
 
Gmane
From: Marek Safar (marek.safar <at> gmail.com) <mono-patches <at> lists.ximian.com>
Subject: [mono/mono] [3 commits] ad78b706: Report error about missing async support types
Newsgroups: gmane.comp.gnome.mono.patches
Date: Monday 19th September 2011 18:35:21 UTC (over 5 years ago)
Branch: refs/heads/master
     Home: https://github.com/mono/mono

   Commit: ad78b706d9a71ab95a76ad8f1d6c0db5ff99869b
   Author: Marek Safar 
     Date: 09/19/2011 14:34:26
      URL: https://github.com/mono/mono/commit/ad78b706d9a71ab95a76ad8f1d6c0db5ff99869b

Report error about missing async support types

Changed paths:
 M mcs/mcs/async.cs
Added paths:
 A mcs/errors/cs1993.cs

Modified: mcs/mcs/async.cs
===================================================================
--- a/mcs/mcs/async.cs
+++ b/mcs/mcs/async.cs
@@ -645,22 +645,26 @@ namespace Mono.CSharp
 				bf = pred_members.AsyncTaskMethodBuilderCreate;
 				sr = pred_members.AsyncTaskMethodBuilderSetResult;
 				se = pred_members.AsyncTaskMethodBuilderSetException;
-				task = pred_members.AsyncTaskMethodBuilderTask.Resolve (Location);
+				task = pred_members.AsyncTaskMethodBuilderTask.Get ();
 			} else {
 				builder_type = Module.PredefinedTypes.AsyncTaskMethodBuilderGeneric;
 				bf = pred_members.AsyncTaskMethodBuilderGenericCreate;
 				sr = pred_members.AsyncTaskMethodBuilderGenericSetResult;
 				se = pred_members.AsyncTaskMethodBuilderGenericSetException;
-				task = pred_members.AsyncTaskMethodBuilderGenericTask.Resolve
(Location);
+				task = pred_members.AsyncTaskMethodBuilderGenericTask.Get ();
 				has_task_return_type = true;
 			}
 
-			set_result = sr.Resolve (Location);
-			set_exception = se.Resolve (Location);
-			var builder_factory = bf.Resolve (Location);
-			var bt = builder_type.Resolve ();
-			if (bt == null || set_result == null || builder_factory == null ||
set_exception == null)
-				return false;
+			set_result = sr.Get ();
+			set_exception = se.Get ();
+			var builder_factory = bf.Get ();
+			if (!builder_type.Define () || set_result == null || builder_factory ==
null || set_exception == null) {
+				Report.Error (1993, Location,
+					"Cannot find compiler required types for asynchronous functions
support. Are you targeting the wrong framework version?");
+				return base.DoDefineMembers ();
+			}
+
+			var bt = builder_type.TypeSpec;
 
 			//
 			// Inflate generic Task types

Added: mcs/errors/cs1993.cs
===================================================================
--- /dev/null
+++ b/mcs/errors/cs1993.cs
@@ -0,0 +1,44 @@
+// CS1993: Cannot find compiler required types for asynchronous functions
support. Are you targeting the wrong framework version?
+// Line: 38
+// Compiler options: -langversion:future -sdk:2
+
+using System.Threading.Tasks;
+
+namespace System.Threading.Tasks
+{
+	class Task
+	{
+	}
+}
+
+static class S
+{
+	public static A GetAwaiter (this int i)
+	{
+		return new A ();
+	}
+}
+
+class A
+{
+	bool IsCompleted {
+		get {
+			return true;
+		}
+	}
+	
+	void OnCompleted (System.Action a)
+	{
+	}
+	
+	int GetResult ()
+	{
+		return 3;
+	}
+	
+	static async Task Test ()
+	{
+		return await 2;
+	}
+}
+



   Commit: e1c66efea89da6ea5b9c148bd52e6c464fbea0b7
   Author: Marek Safar 
     Date: 09/19/2011 14:34:27
      URL: https://github.com/mono/mono/commit/e1c66efea89da6ea5b9c148bd52e6c464fbea0b7

Add 4.5 readonly collection interfaces

Changed paths:
 M mcs/class/corlib/System.Collections.Generic/Dictionary.cs
 M mcs/class/corlib/System.Collections.Generic/List.cs
 M mcs/class/corlib/System.Collections.ObjectModel/Collection.cs
 M mcs/class/corlib/System.Collections.ObjectModel/ReadOnlyCollection.cs
 M mcs/class/corlib/corlib.dll.sources
Added paths:
 A mcs/class/corlib/System.Collections.Generic/IReadOnlyDictionary.cs
 A mcs/class/corlib/System.Collections.Generic/IReadOnlyList.cs

Modified: mcs/class/corlib/System.Collections.Generic/Dictionary.cs
===================================================================
--- a/mcs/class/corlib/System.Collections.Generic/Dictionary.cs
+++ b/mcs/class/corlib/System.Collections.Generic/Dictionary.cs
@@ -12,6 +12,7 @@
 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
 // Copyright (C) 2005 David Waite
 // Copyright (C) 2007 HotFeet GmbH (http://www.hotfeet.ch)
+// Copyright (C) 2011 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
@@ -57,13 +58,10 @@ namespace System.Collections.Generic {
 	[Serializable]
 	[DebuggerDisplay ("Count={Count}")]
 	[DebuggerTypeProxy (typeof (CollectionDebuggerView<,>))]
-	public class Dictionary : IDictionary,
-		IDictionary,
-		ICollection,
-		ICollection>,
-		IEnumerable>,
-		ISerializable,
-		IDeserializationCallback
+	public class Dictionary : IDictionary,
IDictionary, ISerializable, IDeserializationCallback
+#if NET_4_5
+		, IReadOnlyDictionary
+#endif
 	{
 		// The implementation of this class uses a hash table and linked lists
 		// (see: http://msdn2.microsoft.com/en-us/library/ms379571(VS.80).aspx).
@@ -642,6 +640,16 @@ namespace System.Collections.Generic {
 		ICollection IDictionary.Values {
 			get { return Values; }
 		}
+		
+#if NET_4_5
+		IEnumerable IReadOnlyDictionary.Keys {
+			get { return Keys; }
+		}
+ 
+		IEnumerable IReadOnlyDictionary.Values {
+			get { return Values; }
+		}
+#endif
 
 		public KeyCollection Keys {
 			get { return new KeyCollection (this); }
Modified: mcs/class/corlib/System.Collections.Generic/List.cs
===================================================================
--- a/mcs/class/corlib/System.Collections.Generic/List.cs
+++ b/mcs/class/corlib/System.Collections.Generic/List.cs
@@ -6,9 +6,11 @@
 //    Martin Baulig ([email protected])
 //    Carlos Alberto Cortez ([email protected])
 //    David Waite ([email protected])
+//    Marek Safar ([email protected])
 //
 // Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
 // Copyright (C) 2005 David Waite
+// Copyright (C) 2011 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
@@ -38,7 +40,11 @@ namespace System.Collections.Generic {
 	[Serializable]
 	[DebuggerDisplay ("Count={Count}")]
 	[DebuggerTypeProxy (typeof (CollectionDebuggerView<>))]
-	public class List  : IList , IList, ICollection {
+	public class List : IList, IList
+#if NET_4_5
+		, IReadOnlyList
+#endif
+	{
 		T [] _items;
 		int _size;
 		int _version;
Modified: mcs/class/corlib/System.Collections.ObjectModel/Collection.cs
===================================================================
--- a/mcs/class/corlib/System.Collections.ObjectModel/Collection.cs
+++ b/mcs/class/corlib/System.Collections.ObjectModel/Collection.cs
@@ -2,9 +2,10 @@
 //
 // System.Collections.ObjectModel.Collection
 //
-// Author:
+// Authors:
 //    Zoltan Varga ([email protected])
 //    David Waite ([email protected])
+//    Marek Safar ([email protected])
 //
 // (C) 2005 Novell, Inc.
 // (C) 2005 David Waite
@@ -13,6 +14,7 @@
 //
 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
 // Copyright (C) 2005 David Waite
+// Copyright (C) 2011 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
@@ -45,8 +47,11 @@ namespace System.Collections.ObjectModel
 	[ComVisible (false)]
 	[Serializable]
 	[DebuggerDisplay ("Count={Count}")]
-	[DebuggerTypeProxy (typeof (CollectionDebuggerView<>))]	
-	public class Collection  : IList , ICollection , IEnumerable
, IList, ICollection, IEnumerable
+	[DebuggerTypeProxy (typeof (CollectionDebuggerView<>))]
+	public class Collection : IList, IList
+#if NET_4_5
+		, IReadOnlyList
+#endif
 	{
 		IList  list;
 		object syncRoot;
Modified:
mcs/class/corlib/System.Collections.ObjectModel/ReadOnlyCollection.cs
===================================================================
--- a/mcs/class/corlib/System.Collections.ObjectModel/ReadOnlyCollection.cs
+++ b/mcs/class/corlib/System.Collections.ObjectModel/ReadOnlyCollection.cs
@@ -2,9 +2,10 @@
 //
 // System.Collections.ObjectModel.ReadOnlyCollection
 //
-// Author:
+// Authors:
 //    Zoltan Varga ([email protected])
 //    David Waite ([email protected])
+//    Marek Safar ([email protected])
 //
 // (C) 2005 Novell, Inc.
 // (C) 2005 David Waite
@@ -13,6 +14,7 @@
 //
 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
 // Copyright (C) 2005 David Waite
+// Copyright (C) 2011 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
@@ -44,8 +46,11 @@ namespace System.Collections.ObjectModel
 	[ComVisible (false)]
 	[Serializable]
 	[DebuggerDisplay ("Count={Count}")]
-	[DebuggerTypeProxy (typeof (CollectionDebuggerView<>))]	
-	public class ReadOnlyCollection  : IList , ICollection ,
IEnumerable , IList, ICollection, IEnumerable
+	[DebuggerTypeProxy (typeof (CollectionDebuggerView<>))]
+	public class ReadOnlyCollection : IList, IList
+#if NET_4_5
+		, IReadOnlyList
+#endif
 	{
 		IList  list;
 		
Modified: mcs/class/corlib/corlib.dll.sources
===================================================================
--- a/mcs/class/corlib/corlib.dll.sources
+++ b/mcs/class/corlib/corlib.dll.sources
@@ -1521,6 +1521,8 @@ System.Collections.Generic/IList.cs
 System.Collections.Generic/IComparer.cs
 System.Collections.Generic/IEqualityComparer.cs
 System.Collections.Generic/IDictionary.cs
+System.Collections.Generic/IReadOnlyList.cs
+System.Collections.Generic/IReadOnlyDictionary.cs
 System.Collections.Generic/KeyValuePair.cs
 System.Collections.Generic/EqualityComparer.cs
 System.Collections.Generic/KeyNotFoundException.cs

Added: mcs/class/corlib/System.Collections.Generic/IReadOnlyDictionary.cs
===================================================================
--- /dev/null
+++ b/mcs/class/corlib/System.Collections.Generic/IReadOnlyDictionary.cs
@@ -0,0 +1,45 @@
+//
+// IReadOnlyDictionary.cs
+//
+// Authors:
+//	Marek Safar  
+//
+// Copyright (C) 2011 Xamarin, Inc (http://www.xamarin.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+#if NET_4_5
+
+namespace System.Collections.Generic
+{
+	public interface IReadOnlyDictionary :
IEnumerable>
+	{
+		int Count { get; }
+		TValue this [TKey key] { get; }
+		IEnumerable Keys { get; }
+		IEnumerable Values { get; }
+
+		bool ContainsKey (TKey key);
+		bool TryGetValue (TKey key, out TValue value);
+	}
+}
+
+#endif

Added: mcs/class/corlib/System.Collections.Generic/IReadOnlyList.cs
===================================================================
--- /dev/null
+++ b/mcs/class/corlib/System.Collections.Generic/IReadOnlyList.cs
@@ -0,0 +1,40 @@
+//
+// IReadOnlyList.cs
+//
+// Authors:
+//	Marek Safar  
+//
+// Copyright (C) 2011 Xamarin, Inc (http://www.xamarin.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+#if NET_4_5
+
+namespace System.Collections.Generic
+{
+	public interface IReadOnlyList : IEnumerable
+	{
+		int Count { get; }
+		T this [int index] { get; }
+	}
+}
+
+#endif



   Commit: 11db01b5a136988b91a979e6dce4b686c1386418
   Author: Marek Safar 
     Date: 09/19/2011 14:34:27
      URL: https://github.com/mono/mono/commit/11db01b5a136988b91a979e6dce4b686c1386418

Add few new 4.5 overloads

Changed paths:
 M mcs/class/corlib/System.Diagnostics.Contracts.Internal/ContractHelper.cs
 M mcs/class/corlib/System.IO/BinaryReader.cs
 M mcs/class/corlib/System.IO/BinaryWriter.cs
 M mcs/class/corlib/System.IO/MemoryStream.cs
 M mcs/class/corlib/System.IO/Stream.cs
 M mcs/class/corlib/System.IO/StreamReader.cs
 M mcs/class/corlib/System.IO/StreamWriter.cs
 M mcs/class/corlib/corlib.dll.sources
Added paths:
 A mcs/class/corlib/System.Runtime.CompilerServices/ContractHelper.cs
 A mcs/class/corlib/System/IProgress.cs

Modified:
mcs/class/corlib/System.Diagnostics.Contracts.Internal/ContractHelper.cs
===================================================================
---
a/mcs/class/corlib/System.Diagnostics.Contracts.Internal/ContractHelper.cs
+++
b/mcs/class/corlib/System.Diagnostics.Contracts.Internal/ContractHelper.cs
@@ -35,6 +35,7 @@ using System.Runtime.ConstrainedExecution;
 
 namespace System.Diagnostics.Contracts.Internal
 {
+	[Obsolete ("Type has been moved to System.Runtime.CompilerServices")]
 	public static class ContractHelper
 	{
 #if MOONLIGHT
Modified: mcs/class/corlib/System.IO/BinaryReader.cs
===================================================================
--- a/mcs/class/corlib/System.IO/BinaryReader.cs
+++ b/mcs/class/corlib/System.IO/BinaryReader.cs
@@ -9,6 +9,7 @@
 
 //
 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+// Copyright 2011 Xamarin Inc.
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
@@ -55,11 +56,27 @@ namespace System.IO {
 
 		
 		private bool m_disposed;
-
-		public BinaryReader(Stream input) : this(input,
Encoding.UTF8UnmarkedUnsafe) {
+		
+		public BinaryReader(Stream input) 
+			: this(input, Encoding.UTF8UnmarkedUnsafe)
+		{
 		}
-
-		public BinaryReader(Stream input, Encoding encoding) {
+		
+#if NET_4_5
+		readonly bool leave_open;
+		
+		public BinaryReader(Stream input, Encoding encoding)
+			: this (input, encoding, false)
+		{
+		}
+		
+		public BinaryReader(Stream input, Encoding encoding, bool leaveOpen)
+#else
+		const bool leave_open = false;
+		
+		public BinaryReader(Stream input, Encoding encoding)
+#endif
+		{
 			if (input == null || encoding == null) 
 				throw new ArgumentNullException(Locale.GetText ("Input or Encoding is
a null reference."));
 			if (!input.CanRead)
@@ -67,6 +84,9 @@ namespace System.IO {
 
 			m_stream = input;
 			m_encoding = encoding;
+#if NET_4_5
+			leave_open = leaveOpen;
+#endif
 			decoder = encoding.GetDecoder ();
 			
 			// internal buffer size is documented to be between 16 and the value
@@ -87,7 +107,7 @@ namespace System.IO {
 		
 		protected virtual void Dispose (bool disposing)
 		{
-			if (disposing && m_stream != null)
+			if (disposing && m_stream != null && !leave_open)
 				m_stream.Close ();
 
 			m_disposed = true;
Modified: mcs/class/corlib/System.IO/BinaryWriter.cs
===================================================================
--- a/mcs/class/corlib/System.IO/BinaryWriter.cs
+++ b/mcs/class/corlib/System.IO/BinaryWriter.cs
@@ -1,12 +1,14 @@
 //
 // System.IO.BinaryWriter
 //
-// Author:
+// Authors:
 //   Matt Kimball ([email protected])
+//   Marek Safar ([email protected])
 //
 
 //
 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+// Copyright 2011 Xamarin Inc.
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
@@ -47,15 +49,31 @@ namespace System.IO {
 		private byte [] buffer;
 		byte [] stringBuffer;
 		int maxCharsPerRound;
-		private bool disposed = false;
+		bool disposed;
 
-		protected BinaryWriter() : this (Stream.Null,
Encoding.UTF8UnmarkedUnsafe) {
+		protected BinaryWriter() : this (Stream.Null,
Encoding.UTF8UnmarkedUnsafe)
+		{
 		}
 
-		public BinaryWriter(Stream output) : this(output,
Encoding.UTF8UnmarkedUnsafe) {
+		public BinaryWriter(Stream output) : this(output,
Encoding.UTF8UnmarkedUnsafe)
+		{
 		}
-
-		public BinaryWriter(Stream output, Encoding encoding) {
+		
+#if NET_4_5
+		readonly bool leave_open;
+		
+		public BinaryWriter(Stream output, Encoding encoding)
+			: this (output, encoding, false)
+		{
+		}
+		
+		public BinaryWriter(Stream output, Encoding encoding, bool leaveOpen)
+#else
+		const bool leave_open = false;
+		
+		public BinaryWriter(Stream output, Encoding encoding)
+#endif
+		{
 			if (output == null) 
 				throw new ArgumentNullException("output");
 			if (encoding == null) 
@@ -63,6 +81,9 @@ namespace System.IO {
 			if (!output.CanWrite)
 				throw new ArgumentException(Locale.GetText ("Stream does not support
writing or already closed."));
 
+#if NET_4_5
+			leave_open = leaveOpen;
+#endif
 			OutStream = output;
 			m_encoding = encoding;
 			buffer = new byte [16];
@@ -90,7 +111,7 @@ namespace System.IO {
 
 		protected virtual void Dispose (bool disposing)
 		{
-			if (disposing && OutStream != null)
+			if (disposing && OutStream != null && !leave_open)
 				OutStream.Close();
 			
 			buffer = null;
Modified: mcs/class/corlib/System.IO/MemoryStream.cs
===================================================================
--- a/mcs/class/corlib/System.IO/MemoryStream.cs
+++ b/mcs/class/corlib/System.IO/MemoryStream.cs
@@ -418,11 +418,5 @@ namespace System.IO
 
 			stream.Write (internalBuffer, initialIndex, length - initialIndex);
 		}
-
-#if NET_4_0
-		protected override void ObjectInvariant ()
-		{
-		}
-#endif
 	}               
 }
Modified: mcs/class/corlib/System.IO/Stream.cs
===================================================================
--- a/mcs/class/corlib/System.IO/Stream.cs
+++ b/mcs/class/corlib/System.IO/Stream.cs
@@ -260,6 +260,9 @@ namespace System.IO
 				destination.Write (buffer, 0, nread);
 		}
 
+#if NET_4_5
+		[ObsoleteAttribute("Do not call or override this method")]
+#endif
 		protected virtual void ObjectInvariant ()
 		{
 		}
Modified: mcs/class/corlib/System.IO/StreamReader.cs
===================================================================
--- a/mcs/class/corlib/System.IO/StreamReader.cs
+++ b/mcs/class/corlib/System.IO/StreamReader.cs
@@ -8,10 +8,7 @@
 //
 // (C) Ximian, Inc.  http://www.ximian.com
 // Copyright (C) 2004 Novell (http://www.novell.com)
-//
-
-//
-// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+// Copyright 2011 Xamarin Inc.
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
@@ -137,9 +134,25 @@ namespace System.IO {
 
 		public StreamReader(Stream stream, Encoding encoding, bool
detectEncodingFromByteOrderMarks)
 			: this (stream, encoding, detectEncodingFromByteOrderMarks,
DefaultBufferSize) { }
-		
+
+#if NET_4_5
+		readonly bool leave_open;
+
+		public StreamReader(Stream stream, Encoding encoding, bool
detectEncodingFromByteOrderMarks, int bufferSize)
+			: this (stream, encoding, detectEncodingFromByteOrderMarks, bufferSize,
false)
+		{
+		}
+
+		public StreamReader(Stream stream, Encoding encoding, bool
detectEncodingFromByteOrderMarks, int bufferSize, bool leaveOpen)
+#else
+		const bool leave_open = false;
+
 		public StreamReader(Stream stream, Encoding encoding, bool
detectEncodingFromByteOrderMarks, int bufferSize)
+#endif
 		{
+#if NET_4_5
+			leave_open = leaveOpen;
+#endif
 			Initialize (stream, encoding, detectEncodingFromByteOrderMarks,
bufferSize);
 		}
 
@@ -259,7 +272,7 @@ namespace System.IO {
 
 		protected override void Dispose (bool disposing)
 		{
-			if (disposing && base_stream != null)
+			if (disposing && base_stream != null && !leave_open)
 				base_stream.Close ();
 			
 			if (input_buffer != null && input_buffer.Length == DefaultBufferSize &&
input_buffer_recycle == null) {
Modified: mcs/class/corlib/System.IO/StreamWriter.cs
===================================================================
--- a/mcs/class/corlib/System.IO/StreamWriter.cs
+++ b/mcs/class/corlib/System.IO/StreamWriter.cs
@@ -4,12 +4,11 @@
 // Authors:
 //   Dietmar Maurer ([email protected])
 //   Paolo Molaro ([email protected])
+//   Marek Safar ([email protected])
 //
 // (C) Ximian, Inc.  http://www.ximian.com
-//
-
-//
 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+// Copyright 2011 Xamarin Inc.
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
@@ -79,7 +78,21 @@ namespace System.IO {
 				preamble_done = true;
 		}
 
-		public StreamWriter (Stream stream, Encoding encoding, int bufferSize) {
+#if NET_4_5
+		readonly bool leave_open;
+
+		public StreamWriter (Stream stream, Encoding encoding, int bufferSize)
+			: this (stream, encoding, bufferSize, false)
+		{
+		}
+		
+		public StreamWriter (Stream stream, Encoding encoding, int bufferSize,
bool leaveOpen)
+#else
+		const bool leave_open = false;
+
+		public StreamWriter (Stream stream, Encoding encoding, int bufferSize)
+#endif
+		{
 			if (null == stream)
 				throw new ArgumentNullException("stream");
 			if (null == encoding)
@@ -89,6 +102,9 @@ namespace System.IO {
 			if (!stream.CanWrite)
 				throw new ArgumentException ("Can not write to stream");
 
+#if NET_4_5
+			leave_open = leaveOpen;
+#endif
 			internalStream = stream;
 
 			Initialize(encoding, bufferSize);
@@ -102,8 +118,9 @@ namespace System.IO {
 
 		public StreamWriter (string path, bool append, Encoding encoding)
 			: this (path, append, encoding, DefaultFileBufferSize) {}
-		
-		public StreamWriter (string path, bool append, Encoding encoding, int
bufferSize) {
+
+		public StreamWriter (string path, bool append, Encoding encoding, int
bufferSize)
+		{
 			if (null == encoding)
 				throw new ArgumentNullException("encoding");
 			if (bufferSize <= 0)
@@ -152,7 +169,7 @@ namespace System.IO {
 		protected override void Dispose (bool disposing) 
 		{
 			Exception exc = null;
-			if (!DisposedAlready && disposing && internalStream != null) {
+			if (!DisposedAlready && disposing && internalStream != null &&
!leave_open) {
 				try {
 					Flush();
 				} catch (Exception e) {
Modified: mcs/class/corlib/corlib.dll.sources
===================================================================
--- a/mcs/class/corlib/corlib.dll.sources
+++ b/mcs/class/corlib/corlib.dll.sources
@@ -182,6 +182,7 @@ System/InvalidCastException.cs
 System/InvalidOperationException.cs
 System/InvalidProgramException.cs
 System/InvalidTimeZoneException.cs
+System/IProgress.cs
 System/IServiceProvider.cs
 System/KnownTerminals.cs
 System/Lazy.cs
@@ -618,6 +619,7 @@
System.Runtime.CompilerServices/CompilerGeneratedAttribute.cs
 System.Runtime.CompilerServices/CompilerGlobalScopeAttribute.cs
 System.Runtime.CompilerServices/CompilerMarshalOverride.cs
 System.Runtime.CompilerServices/ConditionalWeakTable.cs
+System.Runtime.CompilerServices/ContractHelper.cs
 System.Runtime.CompilerServices/CustomConstantAttribute.cs
 System.Runtime.CompilerServices/DateTimeConstantAttribute.cs
 System.Runtime.CompilerServices/DecimalConstantAttribute.cs

Added: mcs/class/corlib/System.Runtime.CompilerServices/ContractHelper.cs
===================================================================
--- /dev/null
+++ b/mcs/class/corlib/System.Runtime.CompilerServices/ContractHelper.cs
@@ -0,0 +1,166 @@
+//
+// ContractHelper.cs
+//
+// Authors:
+//    Chris Bacon ([email protected])
+//
+// Copyright 2010 Novell (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+#if NET_4_5
+
+using System;
+using System.Text;
+using System.Reflection;
+using System.Runtime.ConstrainedExecution;
+using System.Diagnostics.Contracts;
+using System.Diagnostics;
+
+namespace System.Runtime.CompilerServices
+{
+	public static class ContractHelper
+	{
+#if MOONLIGHT
+		const string SystemWindowsBrowser = ", System.Windows.Browser,
Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e";
+		const string HtmlPage = "System.Windows.Browser.HtmlPage" +
SystemWindowsBrowser;
+		const string HtmlWindow = "System.Windows.Browser.HtmlWindow" +
SystemWindowsBrowser;
+		static MethodInfo alert;
+		static object window;
+
+		static ContractHelper ()
+		{
+			Type htmlpage = Type.GetType (HtmlPage);
+			MethodInfo get_window = htmlpage.GetMethod ("get_Window",
BindingFlags.Static | BindingFlags.Public);
+			window = get_window.Invoke (null, null);
+			Type htmlwindow = Type.GetType (HtmlWindow);
+			alert = htmlwindow.GetMethod ("Alert", BindingFlags.Instance |
BindingFlags.Public);
+		}
+#endif
+
+		[ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
+		[DebuggerNonUserCode]
+		public static string RaiseContractFailedEvent (ContractFailureKind
failureKind, string userMessage, string conditionText, Exception
innerException)
+		{
+
+			StringBuilder msg = new StringBuilder (60);
+			switch (failureKind) {
+			case ContractFailureKind.Assert:
+				msg.Append ("Assertion failed");
+				break;
+			case ContractFailureKind.Assume:
+				msg.Append ("Assumption failed");
+				break;
+			case ContractFailureKind.Invariant:
+				msg.Append ("Invariant failed");
+				break;
+			case ContractFailureKind.Postcondition:
+				msg.Append ("Postcondition failed");
+				break;
+			case ContractFailureKind.PostconditionOnException:
+				msg.Append ("Postcondition failed after throwing an exception");
+				break;
+			case ContractFailureKind.Precondition:
+				msg.Append ("Precondition failed");
+				break;
+			default:
+				throw new NotSupportedException ("Not supported: " + failureKind);
+			}
+			if (conditionText != null) {
+				msg.Append (": ");
+				msg.Append (conditionText);
+			} else {
+				msg.Append ('.');
+			}
+			if (userMessage != null) {
+				msg.Append ("  ");
+				msg.Append (userMessage);
+			}
+			string msgString = msg.ToString ();
+
+			Exception handlerException = null;
+			bool unwind = false, handled = false;
+
+			var contractFailed = Contract.InternalContractFailedEvent;
+			if (contractFailed != null) {
+				// Execute all event handlers
+				var handlers = contractFailed.GetInvocationList ();
+				var e = new ContractFailedEventArgs (failureKind, msgString,
conditionText, innerException);
+				foreach (var handler in handlers) {
+					try {
+						handler.DynamicInvoke (null, e);
+					} catch (Exception ex) {
+						e.SetUnwind ();
+						// If multiple handlers throw an exception then the specification
states that it
+						// is undetermined which one becomes the InnerException.
+						handlerException = ex.InnerException;
+					}
+				}
+				unwind = e.Unwind;
+				handled = e.Handled;
+			}
+
+			if (unwind) {
+				Exception ex = innerException ?? handlerException;
+				throw new ContractException (msgString, failureKind, conditionText,
userMessage, ex);
+			}
+
+			return handled ? null : msgString;
+		}
+
+		[ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
+		[DebuggerNonUserCode]
+		public static void TriggerFailure (ContractFailureKind kind, string
displayMessage, string userMessage, string conditionText, Exception
innerException)
+		{
+			StringBuilder msg = new StringBuilder (50);
+
+			if (conditionText != null) {
+				msg.Append ("Expression: ");
+				msg.AppendLine (conditionText);
+			}
+			msg.Append ("Description: ");
+			if (displayMessage != null) {
+				msg.Append (displayMessage);
+			}
+#if MOONLIGHT
+			// Silverlight shows a dialog that let you Abort (kill
process/browser), Retry or Ignore
+			// Moonlight will simply warn and ignore (at least until FailFast is
implemented)
+			// using reflection into System.Windows.Browser to popup an browser
alert
+			alert.Invoke (window, new object [] { msg.ToString () });
+#else
+			if (Environment.UserInteractive) {
+				// FIXME: This should trigger an assertion.
+				// But code will never get here at the moment, as
Environment.UserInteractive currently
+				// always returns false.
+				throw new ContractShouldAssertException (msg.ToString ());
+			} else {
+				// Note that FailFast() currently throws a NotImplementedException()
+				Environment.FailFast(msg.ToString()/*, new
ExecutionEngineException()*/);
+			}
+#endif
+		}
+
+	}
+
+}
+
+#endif
+

Added: mcs/class/corlib/System/IProgress.cs
===================================================================
--- /dev/null
+++ b/mcs/class/corlib/System/IProgress.cs
@@ -0,0 +1,39 @@
+//
+// IProgress.cs
+//
+// Authors:
+//	Marek Safar  
+//
+// Copyright (C) 2011 Xamarin, Inc (http://www.xamarin.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+#if NET_4_5
+
+namespace System
+{
+	public interface IProgress
+	{
+		void Report (T value);
+	}
+}
+
+#endif





_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches
 
CD: 3ms