Pārlūkot izejas kodu

Add 4.5 readonly collection interfaces

Marek Safar 14 gadi atpakaļ
vecāks
revīzija
e1c66efea8

+ 15 - 7
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<TKey, TValue> : IDictionary<TKey, TValue>,
-		IDictionary,
-		ICollection,
-		ICollection<KeyValuePair<TKey, TValue>>,
-		IEnumerable<KeyValuePair<TKey, TValue>>,
-		ISerializable,
-		IDeserializationCallback
+	public class Dictionary<TKey, TValue> : IDictionary<TKey, TValue>, IDictionary, ISerializable, IDeserializationCallback
+#if NET_4_5
+		, IReadOnlyDictionary<TKey, TValue>
+#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<TValue> IDictionary<TKey, TValue>.Values {
 			get { return Values; }
 		}
+		
+#if NET_4_5
+		IEnumerable<TKey> IReadOnlyDictionary<TKey, TValue>.Keys {
+			get { return Keys; }
+		}
+ 
+		IEnumerable<TValue> IReadOnlyDictionary<TKey, TValue>.Values {
+			get { return Values; }
+		}
+#endif
 
 		public KeyCollection Keys {
 			get { return new KeyCollection (this); }

+ 45 - 0
mcs/class/corlib/System.Collections.Generic/IReadOnlyDictionary.cs

@@ -0,0 +1,45 @@
+//
+// IReadOnlyDictionary.cs
+//
+// Authors:
+//	Marek Safar  <[email protected]>
+//
+// 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<TKey, TValue> : IEnumerable<KeyValuePair<TKey, TValue>>
+	{
+		int Count { get; }
+		TValue this [TKey key] { get; }
+		IEnumerable<TKey> Keys { get; }
+		IEnumerable<TValue> Values { get; }
+
+		bool ContainsKey (TKey key);
+		bool TryGetValue (TKey key, out TValue value);
+	}
+}
+
+#endif

+ 40 - 0
mcs/class/corlib/System.Collections.Generic/IReadOnlyList.cs

@@ -0,0 +1,40 @@
+//
+// IReadOnlyList.cs
+//
+// Authors:
+//	Marek Safar  <[email protected]>
+//
+// 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<out T> : IEnumerable<T>
+	{
+		int Count { get; }
+		T this [int index] { get; }
+	}
+}
+
+#endif

+ 7 - 1
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 <T> : IList <T>, IList, ICollection {
+	public class List<T> : IList<T>, IList
+#if NET_4_5
+		, IReadOnlyList<T>
+#endif
+	{
 		T [] _items;
 		int _size;
 		int _version;

+ 8 - 3
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 <T> : IList <T>, ICollection <T>, IEnumerable <T>, IList, ICollection, IEnumerable
+	[DebuggerTypeProxy (typeof (CollectionDebuggerView<>))]
+	public class Collection<T> : IList<T>, IList
+#if NET_4_5
+		, IReadOnlyList<T>
+#endif
 	{
 		IList <T> list;
 		object syncRoot;

+ 8 - 3
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 <T> : IList <T>, ICollection <T>, IEnumerable <T>, IList, ICollection, IEnumerable
+	[DebuggerTypeProxy (typeof (CollectionDebuggerView<>))]
+	public class ReadOnlyCollection<T> : IList<T>, IList
+#if NET_4_5
+		, IReadOnlyList<T>
+#endif
 	{
 		IList <T> list;
 		

+ 2 - 0
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