Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'mcs/class/System.ComponentModel.Composition/src/ComponentModel/Microsoft/Internal/Collections')
-rw-r--r--mcs/class/System.ComponentModel.Composition/src/ComponentModel/Microsoft/Internal/Collections/.gitattributes7
-rw-r--r--mcs/class/System.ComponentModel.Composition/src/ComponentModel/Microsoft/Internal/Collections/CollectionServices.CollectionOfObject.cs145
-rw-r--r--mcs/class/System.ComponentModel.Composition/src/ComponentModel/Microsoft/Internal/Collections/CollectionServices.cs181
-rw-r--r--mcs/class/System.ComponentModel.Composition/src/ComponentModel/Microsoft/Internal/Collections/ConditionalWeakTable.cs116
-rw-r--r--mcs/class/System.ComponentModel.Composition/src/ComponentModel/Microsoft/Internal/Collections/EnumerableCardinality.cs14
-rw-r--r--mcs/class/System.ComponentModel.Composition/src/ComponentModel/Microsoft/Internal/Collections/ReadOnlyDictionary.cs103
-rw-r--r--mcs/class/System.ComponentModel.Composition/src/ComponentModel/Microsoft/Internal/Collections/ReadOnlyDictionaryDebuggerProxy.cs32
-rw-r--r--mcs/class/System.ComponentModel.Composition/src/ComponentModel/Microsoft/Internal/Collections/WeakReferenceCollection.cs92
8 files changed, 0 insertions, 690 deletions
diff --git a/mcs/class/System.ComponentModel.Composition/src/ComponentModel/Microsoft/Internal/Collections/.gitattributes b/mcs/class/System.ComponentModel.Composition/src/ComponentModel/Microsoft/Internal/Collections/.gitattributes
deleted file mode 100644
index 71f35810375..00000000000
--- a/mcs/class/System.ComponentModel.Composition/src/ComponentModel/Microsoft/Internal/Collections/.gitattributes
+++ /dev/null
@@ -1,7 +0,0 @@
-/CollectionServices.CollectionOfObject.cs -crlf
-/CollectionServices.cs -crlf
-/ConditionalWeakTable.cs -crlf
-/EnumerableCardinality.cs -crlf
-/ReadOnlyDictionary.cs -crlf
-/ReadOnlyDictionaryDebuggerProxy.cs -crlf
-/WeakReferenceCollection.cs -crlf
diff --git a/mcs/class/System.ComponentModel.Composition/src/ComponentModel/Microsoft/Internal/Collections/CollectionServices.CollectionOfObject.cs b/mcs/class/System.ComponentModel.Composition/src/ComponentModel/Microsoft/Internal/Collections/CollectionServices.CollectionOfObject.cs
deleted file mode 100644
index a915efc0016..00000000000
--- a/mcs/class/System.ComponentModel.Composition/src/ComponentModel/Microsoft/Internal/Collections/CollectionServices.CollectionOfObject.cs
+++ /dev/null
@@ -1,145 +0,0 @@
-// -----------------------------------------------------------------------
-// Copyright (c) Microsoft Corporation. All rights reserved.
-// -----------------------------------------------------------------------
-using System;
-using System.Collections;
-using System.Collections.Generic;
-using System.Reflection;
-
-namespace Microsoft.Internal.Collections
-{
- internal static partial class CollectionServices
- {
- public static ICollection<object> GetCollectionWrapper(Type itemType, object collectionObject)
- {
- Assumes.NotNull(itemType, collectionObject);
-
- if (itemType == typeof(object))
- {
- return (ICollection<object>)collectionObject;
- }
-
- // Most common .Net collections implement IList as well so for those
- // cases we can optimize the wrapping instead of using reflection to create
- // a generic type.
- if (typeof(IList).IsAssignableFrom(collectionObject.GetType()))
- {
- return new CollectionOfObjectList((IList)collectionObject);
- }
-
- Type collectionType = typeof(CollectionOfObject<>).MakeGenericType(itemType);
-
- return (ICollection<object>)Activator.CreateInstance(collectionType, collectionObject);
- }
-
- private class CollectionOfObjectList : ICollection<object>
- {
- private readonly IList _list;
-
- public CollectionOfObjectList(IList list)
- {
- this._list = list;
- }
-
- public void Add(object item)
- {
- this._list.Add(item);
- }
-
- public void Clear()
- {
- this._list.Clear();
- }
-
- public bool Contains(object item)
- {
- return Assumes.NotReachable<bool>();
- }
-
- public void CopyTo(object[] array, int arrayIndex)
- {
- Assumes.NotReachable<object>();
- }
-
- public int Count
- {
- get { return Assumes.NotReachable<int>(); }
- }
-
- public bool IsReadOnly
- {
- get { return this._list.IsReadOnly; }
- }
-
- public bool Remove(object item)
- {
- return Assumes.NotReachable<bool>();
- }
-
- public IEnumerator<object> GetEnumerator()
- {
- return Assumes.NotReachable<IEnumerator<object>>();
- }
-
- IEnumerator IEnumerable.GetEnumerator()
- {
- return Assumes.NotReachable<IEnumerator>();
- }
- }
-
- private class CollectionOfObject<T> : ICollection<object>
- {
- private readonly ICollection<T> _collectionOfT;
-
- public CollectionOfObject(object collectionOfT)
- {
- this._collectionOfT = (ICollection<T>)collectionOfT;
- }
-
- public void Add(object item)
- {
- this._collectionOfT.Add((T) item);
- }
-
- public void Clear()
- {
- this._collectionOfT.Clear();
- }
-
- public bool Contains(object item)
- {
- return Assumes.NotReachable<bool>();
- }
-
- public void CopyTo(object[] array, int arrayIndex)
- {
- Assumes.NotReachable<object>();
- }
-
- public int Count
- {
- get { return Assumes.NotReachable<int>(); }
- }
-
- public bool IsReadOnly
- {
- get { return this._collectionOfT.IsReadOnly; }
- }
-
- public bool Remove(object item)
- {
- return Assumes.NotReachable<bool>();
- }
-
- public IEnumerator<object> GetEnumerator()
- {
- return Assumes.NotReachable<IEnumerator<object>>();
- }
-
- IEnumerator IEnumerable.GetEnumerator()
- {
- return Assumes.NotReachable<IEnumerator>();
- }
- }
- }
-}
diff --git a/mcs/class/System.ComponentModel.Composition/src/ComponentModel/Microsoft/Internal/Collections/CollectionServices.cs b/mcs/class/System.ComponentModel.Composition/src/ComponentModel/Microsoft/Internal/Collections/CollectionServices.cs
deleted file mode 100644
index 33fabda0602..00000000000
--- a/mcs/class/System.ComponentModel.Composition/src/ComponentModel/Microsoft/Internal/Collections/CollectionServices.cs
+++ /dev/null
@@ -1,181 +0,0 @@
-// -----------------------------------------------------------------------
-// Copyright (c) Microsoft Corporation. All rights reserved.
-// -----------------------------------------------------------------------
-using System;
-using System.Collections;
-using System.Collections.Generic;
-using System.Collections.ObjectModel;
-using System.Diagnostics.CodeAnalysis;
-using System.Globalization;
-using System.Linq;
-
-namespace Microsoft.Internal.Collections
-{
- internal static partial class CollectionServices
- {
- private static readonly Type StringType = typeof(string);
- private static readonly Type IEnumerableType = typeof(IEnumerable);
- private static readonly Type IEnumerableOfTType = typeof(IEnumerable<>);
- private static readonly Type ICollectionOfTType = typeof(ICollection<>);
-
- public static bool IsEnumerableOfT(Type type)
- {
- if (type.IsGenericType)
- {
- Type genericType = type.GetGenericTypeDefinition();
-
- if (genericType == IEnumerableOfTType)
- {
- return true;
- }
- }
- return false;
- }
-
- public static Type GetEnumerableElementType(Type type)
- {
- if (type == StringType || !IEnumerableType.IsAssignableFrom(type))
- {
- return null;
- }
-
- Type closedType;
- if (ReflectionServices.TryGetGenericInterfaceType(type, IEnumerableOfTType, out closedType))
- {
- return closedType.GetGenericArguments()[0];
- }
-
- return null;
- }
-
- public static Type GetCollectionElementType(Type type)
- {
- Type closedType;
- if (ReflectionServices.TryGetGenericInterfaceType(type, ICollectionOfTType, out closedType))
- {
- return closedType.GetGenericArguments()[0];
- }
-
- return null;
- }
-
- public static ReadOnlyCollection<T> ToReadOnlyCollection<T>(this IEnumerable<T> source)
- {
- Assumes.NotNull(source);
-
- return new ReadOnlyCollection<T>(source.AsArray());
- }
-
- public static IEnumerable<T> WhereNotNull<T>(this IEnumerable<T> source) where T : class
- {
- Assumes.NotNull(source);
- return source.Where(NotNull); // Use non-generic NotNull for performance reasons
- }
-
- private static bool NotNull(object element)
- {
- return element != null;
- }
-
- public static IEnumerable<T> ConcatAllowingNull<T>(this IEnumerable<T> source, IEnumerable<T> second)
- {
- if (second == null || !second.FastAny())
- {
- return source;
- }
-
- if (source == null || !source.FastAny())
- {
- return second;
- }
-
- return source.Concat(second);
- }
-
- public static void ForEach<T>(this IEnumerable<T> source, Action<T> action)
- {
- foreach(T t in source)
- {
- action.Invoke(t);
- }
- }
-
- public static EnumerableCardinality GetCardinality<T>(this IEnumerable<T> source)
- {
- Assumes.NotNull(source);
-
- // Cast to ICollection instead of ICollection<T> for performance reasons.
- ICollection collection = source as ICollection;
- if (collection != null)
- {
- switch (collection.Count)
- {
- case 0:
- return EnumerableCardinality.Zero;
-
- case 1:
- return EnumerableCardinality.One;
-
- default:
- return EnumerableCardinality.TwoOrMore;
- }
- }
-
- using (var enumerator = source.GetEnumerator())
- {
- if (!enumerator.MoveNext())
- {
- return EnumerableCardinality.Zero;
- }
-
- if (!enumerator.MoveNext())
- {
- return EnumerableCardinality.One;
- }
-
- return EnumerableCardinality.TwoOrMore;
- }
- }
-
- public static bool FastAny<T>(this IEnumerable<T> source)
- {
- // Enumerable.Any<T> underneath doesn't cast to ICollection,
- // like it does with many of the other LINQ methods.
- // Below is significantly (4x) when mainly working with ICollection
- // sources and a little slower if working with mainly IEnumerable<T>
- // sources.
-
- // Cast to ICollection instead of ICollection<T> for performance reasons.
- ICollection collection = source as ICollection;
- if (collection != null)
- {
- return collection.Count > 0;
- }
-
- return source.Any();
- }
-
- public static Stack<T> Copy<T>(this Stack<T> stack)
- {
- Assumes.NotNull(stack);
-
- // Stack<T>.GetEnumerator walks from top to bottom
- // of the stack, whereas Stack<T>(IEnumerable<T>)
- // pushes to bottom from top, so we need to reverse
- // the stack to get them in the right order.
- return new Stack<T>(stack.Reverse());
- }
-
- public static T[] AsArray<T>(this IEnumerable<T> enumerable)
- {
- T[] array = enumerable as T[];
-
- if (array != null)
- {
- return array;
- }
-
- return enumerable.ToArray();
- }
- }
-}
diff --git a/mcs/class/System.ComponentModel.Composition/src/ComponentModel/Microsoft/Internal/Collections/ConditionalWeakTable.cs b/mcs/class/System.ComponentModel.Composition/src/ComponentModel/Microsoft/Internal/Collections/ConditionalWeakTable.cs
deleted file mode 100644
index d25dad3357b..00000000000
--- a/mcs/class/System.ComponentModel.Composition/src/ComponentModel/Microsoft/Internal/Collections/ConditionalWeakTable.cs
+++ /dev/null
@@ -1,116 +0,0 @@
-// -----------------------------------------------------------------------
-// Copyright (c) Microsoft Corporation. All rights reserved.
-// -----------------------------------------------------------------------
-#if !CLR40
-using System;
-using System.Collections;
-using System.Collections.Generic;
-using System.Linq;
-using Microsoft.Internal;
-using Microsoft.Internal.Collections;
-
-namespace Microsoft.Internal.Collections
-{
- // This is a broken implementation of ConditionalWeakTable that allows us
- // to compile and work on versions of .Net eariler then 4.0. This class is
- // broken when there are circular dependencies between keys and values, which
- // can only be fixed by using some specific CLR 4.0 features.
- // For code samples of the broken behavior see ConditionalWeakTableTests.cs.
- internal class ConditionalWeakTable<TKey, TValue>
- where TKey : class
- where TValue : class
- {
- private readonly Dictionary<object, TValue> _table;
- private int _capacity = 4;
-
- public ConditionalWeakTable()
- {
- this._table = new Dictionary<object, TValue>();
- }
-
- public void Add(TKey key, TValue value)
- {
- CleanupDeadReferences();
- this._table.Add(CreateWeakKey(key), value);
- }
-
- public bool Remove(TKey key)
- {
- return this._table.Remove(key);
- }
-
- public bool TryGetValue(TKey key, out TValue value)
- {
- return this._table.TryGetValue(key, out value);
- }
-
- private void CleanupDeadReferences()
- {
- if (this._table.Count < _capacity)
- {
- return;
- }
-
- object[] deadKeys = this._table.Keys
- .Where(weakRef => !((EquivalentWeakReference)weakRef).IsAlive).ToArray();
-
- foreach (var deadKey in deadKeys)
- {
- this._table.Remove(deadKey);
- }
-
- if (this._table.Count >= _capacity)
- {
- _capacity *= 2;
- }
- }
-
- private static object CreateWeakKey(TKey key)
- {
- return new EquivalentWeakReference(key);
- }
-
- private class EquivalentWeakReference
- {
- private readonly WeakReference _weakReference;
- private readonly int _hashCode;
-
- public EquivalentWeakReference(object obj)
- {
- this._hashCode = obj.GetHashCode();
- this._weakReference = new WeakReference(obj);
- }
-
- public bool IsAlive
- {
- get
- {
- return this._weakReference.IsAlive;
- }
- }
-
- public override bool Equals(object obj)
- {
- EquivalentWeakReference weakRef = obj as EquivalentWeakReference;
-
- if (weakRef != null)
- {
- obj = weakRef._weakReference.Target;
- }
-
- if (obj == null)
- {
- return base.Equals(weakRef);
- }
-
- return object.Equals(this._weakReference.Target, obj);
- }
-
- public override int GetHashCode()
- {
- return this._hashCode;
- }
- }
- }
-}
-#endif \ No newline at end of file
diff --git a/mcs/class/System.ComponentModel.Composition/src/ComponentModel/Microsoft/Internal/Collections/EnumerableCardinality.cs b/mcs/class/System.ComponentModel.Composition/src/ComponentModel/Microsoft/Internal/Collections/EnumerableCardinality.cs
deleted file mode 100644
index 45fc7de01cf..00000000000
--- a/mcs/class/System.ComponentModel.Composition/src/ComponentModel/Microsoft/Internal/Collections/EnumerableCardinality.cs
+++ /dev/null
@@ -1,14 +0,0 @@
-// -----------------------------------------------------------------------
-// Copyright (c) Microsoft Corporation. All rights reserved.
-// -----------------------------------------------------------------------
-using System;
-
-namespace Microsoft.Internal.Collections
-{
- internal enum EnumerableCardinality : int
- {
- Zero = 0,
- One = 1,
- TwoOrMore = 2,
- }
-}
diff --git a/mcs/class/System.ComponentModel.Composition/src/ComponentModel/Microsoft/Internal/Collections/ReadOnlyDictionary.cs b/mcs/class/System.ComponentModel.Composition/src/ComponentModel/Microsoft/Internal/Collections/ReadOnlyDictionary.cs
deleted file mode 100644
index 55da71142b5..00000000000
--- a/mcs/class/System.ComponentModel.Composition/src/ComponentModel/Microsoft/Internal/Collections/ReadOnlyDictionary.cs
+++ /dev/null
@@ -1,103 +0,0 @@
-// -----------------------------------------------------------------------
-// Copyright (c) Microsoft Corporation. All rights reserved.
-// -----------------------------------------------------------------------
-using System;
-using System.Collections;
-using System.Collections.Generic;
-using System.Diagnostics;
-
-namespace Microsoft.Internal.Collections
-{
- [DebuggerDisplay("Count = {Count}")]
- [DebuggerTypeProxy(typeof(ReadOnlyDictionaryDebuggerProxy<,>))]
- internal sealed partial class ReadOnlyDictionary<TKey, TValue> : IDictionary<TKey, TValue>
- {
- private readonly IDictionary<TKey, TValue> _innerDictionary;
-
- public ReadOnlyDictionary(IDictionary<TKey, TValue> dictionary)
- {
- this._innerDictionary = dictionary ?? new Dictionary<TKey, TValue>(0);
- }
-
- public int Count
- {
- get { return this._innerDictionary.Count; }
- }
-
- public bool IsReadOnly
- {
- get { return true; }
- }
-
- public ICollection<TKey> Keys
- {
- get { return this._innerDictionary.Keys; }
- }
-
- public TValue this[TKey key]
- {
- get { return this._innerDictionary[key]; }
- set { throw new NotSupportedException(Strings.NotSupportedReadOnlyDictionary); }
- }
-
- public ICollection<TValue> Values
- {
- get { return this._innerDictionary.Values; }
- }
-
- public bool Contains(KeyValuePair<TKey, TValue> item)
- {
- return this._innerDictionary.Contains(item);
- }
-
- public bool ContainsKey(TKey key)
- {
- return this._innerDictionary.ContainsKey(key);
- }
-
- public void CopyTo(KeyValuePair<TKey, TValue>[] array, int arrayIndex)
- {
- this._innerDictionary.CopyTo(array, arrayIndex);
- }
-
- public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator()
- {
- return this._innerDictionary.GetEnumerator();
- }
-
- public bool TryGetValue(TKey key, out TValue value)
- {
- return this._innerDictionary.TryGetValue(key, out value);
- }
-
- IEnumerator IEnumerable.GetEnumerator()
- {
- return this._innerDictionary.GetEnumerator();
- }
-
- void IDictionary<TKey, TValue>.Add(TKey key, TValue value)
- {
- throw new NotSupportedException(Strings.NotSupportedReadOnlyDictionary);
- }
-
- void ICollection<KeyValuePair<TKey, TValue>>.Add(KeyValuePair<TKey, TValue> item)
- {
- throw new NotSupportedException(Strings.NotSupportedReadOnlyDictionary);
- }
-
- void ICollection<KeyValuePair<TKey, TValue>>.Clear()
- {
- throw new NotSupportedException(Strings.NotSupportedReadOnlyDictionary);
- }
-
- bool IDictionary<TKey, TValue>.Remove(TKey key)
- {
- throw new NotSupportedException(Strings.NotSupportedReadOnlyDictionary);
- }
-
- bool ICollection<KeyValuePair<TKey, TValue>>.Remove(KeyValuePair<TKey, TValue> item)
- {
- throw new NotSupportedException(Strings.NotSupportedReadOnlyDictionary);
- }
- }
-}
diff --git a/mcs/class/System.ComponentModel.Composition/src/ComponentModel/Microsoft/Internal/Collections/ReadOnlyDictionaryDebuggerProxy.cs b/mcs/class/System.ComponentModel.Composition/src/ComponentModel/Microsoft/Internal/Collections/ReadOnlyDictionaryDebuggerProxy.cs
deleted file mode 100644
index 8fa7ad5fcf6..00000000000
--- a/mcs/class/System.ComponentModel.Composition/src/ComponentModel/Microsoft/Internal/Collections/ReadOnlyDictionaryDebuggerProxy.cs
+++ /dev/null
@@ -1,32 +0,0 @@
-// -----------------------------------------------------------------------
-// Copyright (c) Microsoft Corporation. All rights reserved.
-// -----------------------------------------------------------------------
-using System;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.Linq;
-
-namespace Microsoft.Internal.Collections
-{
- // NOTE: This type cannot be a nested proxy of ReadOnlyDictionary due to a bug
- // in the Visual Studio Debugger which causes it to ignore nested generic proxies.
- internal class ReadOnlyDictionaryDebuggerProxy<TKey, TValue>
- {
- private readonly ReadOnlyDictionary<TKey, TValue> _dictionary;
-
- public ReadOnlyDictionaryDebuggerProxy(ReadOnlyDictionary<TKey, TValue> dictionary)
- {
- Requires.NotNull(dictionary, "dictionary");
-
- _dictionary = dictionary;
- }
-
- [DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
- public KeyValuePair<TKey, TValue>[] Items
- {
- // NOTE: This shouldn't be cached, so that on every query of
- // the current value of the underlying dictionary is respected.
- get { return this._dictionary.ToArray(); }
- }
- }
-}
diff --git a/mcs/class/System.ComponentModel.Composition/src/ComponentModel/Microsoft/Internal/Collections/WeakReferenceCollection.cs b/mcs/class/System.ComponentModel.Composition/src/ComponentModel/Microsoft/Internal/Collections/WeakReferenceCollection.cs
deleted file mode 100644
index ce8b55a485c..00000000000
--- a/mcs/class/System.ComponentModel.Composition/src/ComponentModel/Microsoft/Internal/Collections/WeakReferenceCollection.cs
+++ /dev/null
@@ -1,92 +0,0 @@
-// -----------------------------------------------------------------------
-// Copyright (c) Microsoft Corporation. All rights reserved.
-// -----------------------------------------------------------------------
-using System;
-using System.Collections;
-using System.Collections.Generic;
-using System.Linq;
-using Microsoft.Internal;
-using Microsoft.Internal.Collections;
-
-namespace Microsoft.Internal.Collections
-{
- internal class WeakReferenceCollection<T> where T : class
- {
- private readonly List<WeakReference> _items = new List<WeakReference>();
-
- public void Add(T item)
- {
- // Only cleanup right before we need to reallocate space.
- if (this._items.Capacity == this._items.Count)
- {
- this.CleanupDeadReferences();
- }
-
- this._items.Add(new WeakReference(item));
- }
-
- public void Remove(T item)
- {
- int index = IndexOf(item);
-
- if (index != -1)
- {
- this._items.RemoveAt(index);
- }
- }
-
- public bool Contains(T item)
- {
- return IndexOf(item) >= 0;
- }
-
- public void Clear()
- {
- this._items.Clear();
- }
-
- // Should be executed under at least a read lock.
- private int IndexOf(T item)
- {
- int count = this._items.Count;
- for (int i = 0; i < count; i++)
- {
- if (this._items[i].Target == item)
- {
- return i;
- }
- }
- return -1;
- }
-
- // Should be executed under a write lock
- private void CleanupDeadReferences()
- {
- int count = this._items.Count;
- for (int i = count - 1; i >= 0; i--)
- {
- if (this._items[i].Target == null)
- {
- this._items.RemoveAt(i);
- }
- }
- }
-
- public List<T> AliveItemsToList()
- {
- List<T> aliveItems = new List<T>();
-
- foreach (var weakItem in this._items)
- {
- T item = weakItem.Target as T;
-
- if (item != null)
- {
- aliveItems.Add(item);
- }
- }
-
- return aliveItems;
- }
- }
-}