mirror of
https://github.com/BepInEx/mono.git
synced 2026-11-16 01:41:18 -10:00
Clone input collection for ObservableCollection<T>. Fixes #2169
This commit is contained in:
1 parent
c99040b072
commit
a04edc9de8
3 files changed
+52
-11
No files matched your search
@@ -18,11 +18,14 @@
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
// Copyright (c) 2007 Novell, Inc. (http://www.novell.com)
|
||||
// Copyright 2011 Xamarin Inc.
|
||||
//
|
||||
// Authors:
|
||||
// Chris Toshok ([email protected])
|
||||
// Brian O'Keefe ([email protected])
|
||||
// Marek Safar ([email protected])
|
||||
//
|
||||
|
||||
#if NET_4_0 || MOBILE
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
@@ -62,17 +65,21 @@ namespace System.Collections.ObjectModel
|
||||
|
||||
private Reentrant reentrant = new Reentrant ();
|
||||
|
||||
public ObservableCollection()
|
||||
public ObservableCollection ()
|
||||
{
|
||||
}
|
||||
|
||||
public ObservableCollection(IEnumerable<T> collection)
|
||||
public ObservableCollection (IEnumerable<T> collection)
|
||||
{
|
||||
throw new NotImplementedException ();
|
||||
if (collection == null)
|
||||
throw new ArgumentNullException ("collection");
|
||||
|
||||
foreach (var item in collection)
|
||||
Add (item);
|
||||
}
|
||||
|
||||
public ObservableCollection(List<T> list)
|
||||
: base (list)
|
||||
public ObservableCollection (List<T> list)
|
||||
: base (list != null ? new List<T> (list) : null)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -18,10 +18,12 @@
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
// Copyright (c) 2007 Novell, Inc. (http://www.novell.com)
|
||||
// Copyright 2011 Xamarin Inc.
|
||||
//
|
||||
// Authors:
|
||||
// Chris Toshok ([email protected])
|
||||
// Brian O'Keefe ([email protected])
|
||||
// Marek Safar ([email protected])
|
||||
//
|
||||
|
||||
using System.Collections.ObjectModel;
|
||||
@@ -36,10 +38,35 @@ using MonoTests.System.Collections.Specialized;
|
||||
namespace MonoTests.System.Collections.ObjectModel {
|
||||
|
||||
[TestFixture]
|
||||
public class ObservableCollectionTest {
|
||||
|
||||
public ObservableCollectionTest()
|
||||
public class ObservableCollectionTest
|
||||
{
|
||||
[Test]
|
||||
public void Constructor ()
|
||||
{
|
||||
var list = new List<int> { 3 };
|
||||
var col = new ObservableCollection<int> (list);
|
||||
col.Add (5);
|
||||
Assert.AreEqual (1, list.Count, "#1");
|
||||
|
||||
col = new ObservableCollection<int> ((IEnumerable<int>) list);
|
||||
col.Add (5);
|
||||
Assert.AreEqual (1, list.Count, "#2");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Constructor_Invalid ()
|
||||
{
|
||||
try {
|
||||
new ObservableCollection<int> ((List<int>) null);
|
||||
Assert.Fail ("#1");
|
||||
} catch (ArgumentNullException) {
|
||||
}
|
||||
|
||||
try {
|
||||
new ObservableCollection<int> ((IEnumerable<int>) null);
|
||||
Assert.Fail ("#2");
|
||||
} catch (ArgumentNullException) {
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
@@ -18,10 +18,12 @@
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
// Copyright (c) 2007 Novell, Inc. (http://www.novell.com)
|
||||
// Copyright 2011 Xamarin Inc.
|
||||
//
|
||||
// Authors:
|
||||
// Chris Toshok ([email protected])
|
||||
// Brian O'Keefe ([email protected])
|
||||
// Marek Safar ([email protected])
|
||||
//
|
||||
|
||||
#if NET_4_0
|
||||
@@ -36,7 +38,8 @@ using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace System.Collections.ObjectModel {
|
||||
namespace System.Collections.ObjectModel
|
||||
{
|
||||
[Serializable]
|
||||
public class ObservableCollection<T> : Collection<T>, INotifyCollectionChanged, INotifyPropertyChanged {
|
||||
|
||||
@@ -71,11 +74,15 @@ namespace System.Collections.ObjectModel {
|
||||
|
||||
public ObservableCollection(IEnumerable<T> collection)
|
||||
{
|
||||
throw new NotImplementedException ();
|
||||
if (collection == null)
|
||||
throw new ArgumentNullException ("collection");
|
||||
|
||||
foreach (var item in collection)
|
||||
Add (item);
|
||||
}
|
||||
|
||||
public ObservableCollection(List<T> list)
|
||||
: base (list)
|
||||
: base (list != null ? new List<T> (list) : null)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user