From 99364ad83dcf3b0dff713d88e0259a412cd10bca Mon Sep 17 00:00:00 2001 From: David Hall Date: Tue, 11 Dec 2018 11:34:00 -0700 Subject: [PATCH] Removed all backwards compatibility code and instead referenced Theraot.Core. --- Core/BkwdComp/ExtensionAttribute.NET2.cs | 11 - Core/BkwdComp/Func.NET2.cs | 46 -- Core/BkwdComp/HashSet.NET2.cs | 522 --------------------- Core/BkwdComp/Linq.NET2.cs | 474 ------------------- .../System.Collections.Generic.PreNet45.cs | 63 --- .../System.Collections.Specialized.Net20.cs | 142 ------ Core/BkwdComp/Tuple.NET2.cs | 33 -- Core/Vanara.Core.csproj | 5 +- 8 files changed, 4 insertions(+), 1292 deletions(-) delete mode 100644 Core/BkwdComp/ExtensionAttribute.NET2.cs delete mode 100644 Core/BkwdComp/Func.NET2.cs delete mode 100644 Core/BkwdComp/HashSet.NET2.cs delete mode 100644 Core/BkwdComp/Linq.NET2.cs delete mode 100644 Core/BkwdComp/System.Collections.Generic.PreNet45.cs delete mode 100644 Core/BkwdComp/System.Collections.Specialized.Net20.cs delete mode 100644 Core/BkwdComp/Tuple.NET2.cs diff --git a/Core/BkwdComp/ExtensionAttribute.NET2.cs b/Core/BkwdComp/ExtensionAttribute.NET2.cs deleted file mode 100644 index 43357fdf..00000000 --- a/Core/BkwdComp/ExtensionAttribute.NET2.cs +++ /dev/null @@ -1,11 +0,0 @@ -#if (NET20) -namespace System.Runtime.CompilerServices -{ - /// - /// Attribute allowing extenders to be used with .NET Framework 2.0. - /// - public sealed class ExtensionAttribute : Attribute - { - } -} -#endif \ No newline at end of file diff --git a/Core/BkwdComp/Func.NET2.cs b/Core/BkwdComp/Func.NET2.cs deleted file mode 100644 index 097a554e..00000000 --- a/Core/BkwdComp/Func.NET2.cs +++ /dev/null @@ -1,46 +0,0 @@ -#if (NET20) -namespace System -{ - /// Encapsulates a method that returns a value of the type specified by the TResult parameter. - /// The type of the return value of the method that this delegate encapsulates. - /// The return value of the method that this delegate encapsulates. - public delegate TResult Func(); - - /// Encapsulates a method that has one parameter and returns a value of the type specified by the TResult parameter. - /// The type of the parameter of the method that this delegate encapsulates. - /// The type of the return value of the method that this delegate encapsulates. - /// The parameter of the method that this delegate encapsulates. - /// The return value of the method that this delegate encapsulates. - public delegate TResult Func(T arg); - - /// Encapsulates a method that has two parameters and returns a value of the type specified by the TResult parameter. - /// The type of the first parameter of the method that this delegate encapsulates. - /// The type of the second parameter of the method that this delegate encapsulates. - /// The type of the return value of the method that this delegate encapsulates. - /// The first parameter of the method that this delegate encapsulates. - /// The second parameter of the method that this delegate encapsulates. - /// The return value of the method that this delegate encapsulates. - public delegate TResult Func(T1 arg1, T2 arg2); - - /// Encapsulates a method that has two parameters and returns a value of the type specified by the TResult parameter. - /// The type of the first parameter of the method that this delegate encapsulates. - /// The type of the second parameter of the method that this delegate encapsulates. - /// The type of the third parameter of the method that this delegate encapsulates. - /// The type of the return value of the method that this delegate encapsulates. - /// The first parameter of the method that this delegate encapsulates. - /// The second parameter of the method that this delegate encapsulates. - /// The third parameter of the method that this delegate encapsulates. - /// The return value of the method that this delegate encapsulates. - public delegate TResult Func(T1 arg1, T2 arg2, T3 arg3); - - /// Encapsulates a method that has no parameters and does not return a value. - public delegate void Action(); - - /// Encapsulates a method that has two parameters and does not return a value. - /// The type of the first parameter of the method that this delegate encapsulates. - /// The type of the second parameter of the method that this delegate encapsulates. - /// The first parameter of the method that this delegate encapsulates. - /// The second parameter of the method that this delegate encapsulates. - public delegate void Action(T1 arg1, T2 arg2); -} -#endif \ No newline at end of file diff --git a/Core/BkwdComp/HashSet.NET2.cs b/Core/BkwdComp/HashSet.NET2.cs deleted file mode 100644 index 7f62e67d..00000000 --- a/Core/BkwdComp/HashSet.NET2.cs +++ /dev/null @@ -1,522 +0,0 @@ -#if NET20 -using System.Linq; -using System.Runtime.Serialization; - -namespace System.Collections.Generic -{ - /// Provides the base interface for the abstraction of sets. - public interface ISet : ICollection - { - /// Adds an element to the current set and returns a value to indicate if the element was successfully added. - /// The element to add to the set. - /// true if the element is added to the set; false if the element is already in the set. - new bool Add(T item); - - /// Removes all elements in the specified collection from the current set. - /// The collection of items to remove from the set. - void ExceptWith(IEnumerable other); - - /// Modifies the current set so that it contains only elements that are also in a specified collection. - /// The collection to compare to the current set. - void IntersectWith(IEnumerable other); - - /// Determines whether the current set is a proper (strict) subset of a specified collection. - /// The collection to compare to the current set. - /// true if the current set is a proper subset of ; otherwise, false. - bool IsProperSubsetOf(IEnumerable other); - - /// Determines whether the current set is a proper (strict) superset of a specified collection. - /// The collection to compare to the current set. - /// true if the current set is a proper superset of ; otherwise, false. - bool IsProperSupersetOf(IEnumerable other); - - /// Determines whether a set is a subset of a specified collection. - /// The collection to compare to the current set. - /// true if the current set is a subset of ; otherwise, false. - bool IsSubsetOf(IEnumerable other); - - /// Determines whether the current set is a superset of a specified collection. - /// The collection to compare to the current set. - /// true if the current set is a superset of ; otherwise, false. - bool IsSupersetOf(IEnumerable other); - - /// Determines whether the current set overlaps with the specified collection. - /// The collection to compare to the current set. - /// true if the current set and share at least one common element; otherwise, false. - bool Overlaps(IEnumerable other); - - /// Determines whether the current set and the specified collection contain the same elements. - /// The collection to compare to the current set. - /// true if the current set is equal to ; otherwise, false. - bool SetEquals(IEnumerable other); - - /// - /// Modifies the current set so that it contains only elements that are present either in the current set or in the specified - /// collection, but not both. - /// - /// The collection to compare to the current set. - void SymmetricExceptWith(IEnumerable other); - - /// - /// Modifies the current set so that it contains all elements that are present in the current set, in the specified collection, or in both. - /// - /// The collection to compare to the current set. - void UnionWith(IEnumerable other); - } - - /// - /// Represents a set of values. This is less efficient than the native implementation in .NET versions after 2.0, but functionally equivalent. - /// - /// The type of elements in the hash set. - public class HashSet : ISet, IReadOnlyCollection, ISerializable, IDeserializationCallback - { - private readonly Dictionary dict; - - /// - /// Initializes a new instance of the class that is empty and uses the default equality comparer for the set type. - /// - public HashSet() : this((IEqualityComparer)null) - { - } - - /// - /// Initializes a new instance of the class that uses the default equality comparer for the set type, - /// contains elements copied from the specified collection, and has sufficient capacity to accommodate the number of elements copied.. - /// - /// The collection whose elements are copied to the new set. - public HashSet(IEnumerable collection) : this(collection, null) - { - } - - /// - /// Initializes a new instance of the class that is empty and uses the specified equality comparer for the - /// set type.. - /// - /// - /// The implementation to use when comparing values in the set, or null to use the default - /// implementation for the set type. - /// - public HashSet(IEqualityComparer comparer) - { - dict = new Dictionary(comparer); - } - - /// - /// Initializes a new instance of the class that uses the specified equality comparer for the set type, - /// contains elements copied from the specified collection, and has sufficient capacity to accommodate the number of elements copied.. - /// - /// The collection whose elements are copied to the new set. - /// - /// The implementation to use when comparing values in the set, or null to use the default - /// implementation for the set type. - /// - public HashSet(IEnumerable collection, IEqualityComparer comparer) - { - dict = new Dictionary(comparer); - foreach (var elem in collection) - { - Add(elem); - } - } - - /* ***** Unnecessary since implemented in .NET 4.7.2 - /// - /// Initializes a new instance of the class that is empty, but has reserved space for capacity items and - /// uses the default equality comparer for the set type.. - /// - /// The initial size of the - public HashSet(int capacity) : this(capacity, null) - { - } - - /// - /// Initializes a new instance of the class that uses the specified equality comparer for the set type, and - /// has sufficient capacity to accommodate capacity elements.. - /// - /// The initial size of the - /// - /// The implementation to use when comparing values in the set, or null to use the default - /// implementation for the set type. - /// - public HashSet(int capacity, IEqualityComparer comparer) - { - dict = new Dictionary(capacity, comparer); - } - */ - - /// Gets the object that is used to determine equality for the values in the set. - public IEqualityComparer Comparer => dict.Comparer; - - /// - public int Count => dict.Count; - - /// - bool ICollection.IsReadOnly { get; } = false; - - /// - public bool Add(T item) - { - if (null == item) - { - throw new ArgumentNullException(nameof(item)); - } - - if (Contains(item)) - { - return false; - } - - dict[item] = null; - return true; - } - - /// - public void Clear() - { - dict.Clear(); - } - - /// - public bool Contains(T item) - { - return item != null && dict.ContainsKey(item); - } - - /// - public void CopyTo(T[] array, int arrayIndex) - { - if (array == null) - { - throw new ArgumentNullException(nameof(array)); - } - - if (arrayIndex < 0 || arrayIndex >= array.Length || arrayIndex >= Count) - { - throw new ArgumentOutOfRangeException(nameof(arrayIndex)); - } - - dict.Keys.CopyTo(array, arrayIndex); - } - - /// - public void ExceptWith(IEnumerable other) - { - if (other == null) - { - throw new ArgumentNullException(nameof(other)); - } - - if (Count == 0) - { - return; - } - - if (other == this) - { - Clear(); - return; - } - foreach (T elem in other) - { - dict.Remove(elem); - } - } - - /// - public IEnumerator GetEnumerator() - { - return dict.Keys.GetEnumerator(); - } - - /// - public virtual void GetObjectData(SerializationInfo info, StreamingContext context) - { - if (info == null) - { - throw new ArgumentNullException(nameof(info)); - } - - dict.GetObjectData(info, context); - } - - /// - public void IntersectWith(IEnumerable other) - { - if (other == null) - { - throw new ArgumentNullException(nameof(other)); - } - - if (other is ICollection c && c.Count == 0) - { - Clear(); - return; - } - - var l = this.ToList(); - foreach (var elem in l) - { - // ReSharper disable once PossibleMultipleEnumeration - if (!other.Contains(elem)) - { - Remove(elem); - } - } - } - - /// - public bool IsProperSubsetOf(IEnumerable other) - { - if (other == null) - { - throw new ArgumentNullException(nameof(other)); - } - - if (Count == 0 && other is ICollection c) - { - return c.Count > 0; - } - - CheckUniqueAndUnfoundElements(other, out int unique, out int unfound, false); - return unique == Count && unfound > 0; - } - - /// - public bool IsProperSupersetOf(IEnumerable other) - { - if (other == null) - { - throw new ArgumentNullException(nameof(other)); - } - - if (Count == 0) - { - return false; - } - - if (other is ICollection c && c.Count == 0) - { - return true; - } - - CheckUniqueAndUnfoundElements(other, out int unique, out int unfound, true); - return unique < Count && unfound == 0; - } - - /// - public bool IsSubsetOf(IEnumerable other) - { - if (other == null) - { - throw new ArgumentNullException(nameof(other)); - } - - if (Count == 0) - { - return true; - } - - CheckUniqueAndUnfoundElements(other, out int unique, out int unfound, false); - return unique == Count && unfound >= 0; - } - - /// - public bool IsSupersetOf(IEnumerable other) - { - if (other == null) - { - throw new ArgumentNullException(nameof(other)); - } - - if (other is ICollection c && c.Count == 0) - { - return true; - } - - foreach (T elem in other) - { - if (!Contains(elem)) - { - return false; - } - } - - return true; - } - - /// - public virtual void OnDeserialization(object sender) - { - dict.OnDeserialization(sender); - } - - /// - public bool Overlaps(IEnumerable other) - { - if (other == null) - { - throw new ArgumentNullException(nameof(other)); - } - - if (Count == 0) - { - return false; - } - - foreach (T elem in other) - { - if (Contains(elem)) - { - return true; - } - } - - return false; - } - - /// - public bool Remove(T item) - { - return item != null && dict.Remove(item); - } - - /// - public bool SetEquals(IEnumerable other) - { - if (other == null) - { - throw new ArgumentNullException(nameof(other)); - } - - if (other is ICollection c && c.Count != Count) - { - return false; - } - - CheckUniqueAndUnfoundElements(other, out int unique, out int unfound, true); - return unique == Count && unfound == 0; - } - - /// - public void SymmetricExceptWith(IEnumerable other) - { - if (other == null) - { - throw new ArgumentNullException(nameof(other)); - } - - if (Count == 0) - { - UnionWith(other); - return; - } - if (other == this) - { - Clear(); - return; - } - - HashSet oh = new HashSet(other, Comparer); - List dup = this.ToList(); - ExceptWith(oh); - oh.ExceptWith(dup); - UnionWith(oh); - } - - /// Searches the set for a given value and returns the equal value it finds, if any. - /// The value to search for. - /// - /// The value from the set that the search found, or the default value of T when the search yielded no match. - /// - /// A value indicating whether the search was successful. - /// - /// This can be useful when you want to reuse a previously stored reference instead of a newly constructed one (so that more sharing - /// of references can occur) or to look up a value that has more complete data than the value you currently have, although their - /// comparer functions indicate they are equal. - /// - public bool TryGetValue(T equalValue, out T actualValue) - { - foreach (T k in dict.Keys) - { - if (!Comparer.Equals(k, equalValue)) - { - continue; - } - - actualValue = k; - return true; - } - actualValue = default; - return false; - } - - /// - public void UnionWith(IEnumerable other) - { - if (other == null) - { - throw new ArgumentNullException(nameof(other)); - } - - if (this == other) - { - return; - } - - foreach (T elem in other) - { - Add(elem); - } - } - - /// - void ICollection.Add(T item) - { - Add(item); - } - - /// - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - - private void CheckUniqueAndUnfoundElements(IEnumerable other, out int unique, out int unfound, bool returnIfUnfound) - { - if (Count == 0) - { - unique = 0; - unfound = other.Any() ? 1 : 0; - return; - } - - unfound = 0; - unique = 0; - List l = this.ToList(); - BitArray bits = new BitArray(l.Count); - foreach (T o in other) - { - int index = l.IndexOf(o); - if (index >= 0) - { - if (bits[index]) - { - continue; - } - // item hasn't been seen yet - bits[index] = true; - unique++; - } - else - { - unfound++; - if (returnIfUnfound) - { - break; - } - } - } - } - } -} -#endif \ No newline at end of file diff --git a/Core/BkwdComp/Linq.NET2.cs b/Core/BkwdComp/Linq.NET2.cs deleted file mode 100644 index 6a0d18ec..00000000 --- a/Core/BkwdComp/Linq.NET2.cs +++ /dev/null @@ -1,474 +0,0 @@ -#if (NET20) -using System.Collections; -using System.Collections.Generic; - -namespace System.Linq -{ - /// Provides a set of static (Shared in Visual Basic) methods for querying objects that implement . - public static class Enumerable - { - /// Determines whether all elements of a sequence satisfy a condition. - /// The type of the elements of . - /// An whose elements to apply the predicate to. - /// A function to test each element for a condition. - /// true if all elements in the source sequence pass the test in the specified predicate; otherwise, false. - public static bool All(this IEnumerable source, Func predicate) - { - if (source == null) throw new ArgumentNullException(nameof(source)); - if (predicate == null) throw new ArgumentNullException(nameof(predicate)); - foreach (TSource element in source) - if (!predicate(element)) return false; - return true; - } - - /// Determines whether any element of a sequence satisfies a condition. - /// The type of the elements of . - /// An whose elements to apply the predicate to. - /// A function to test each element for a condition. - /// true if any elements in the source sequence pass the test in the specified predicate; otherwise, false. - public static bool Any(this IEnumerable source, Func predicate = null) - { - if (source == null) throw new ArgumentNullException(nameof(source)); - foreach (TSource element in source) - if (predicate == null || predicate(element)) return true; - return false; - } - - /// Casts the elements of an to the specified type. - /// The type to cast the elements of source to. - /// The that contains the elements to be cast to type . - /// An that contains each element of the source sequence cast to the specified type. - public static IEnumerable Cast(this IEnumerable source) - { - foreach (var i in source) - yield return (TResult)i; - } - - /// Determines whether a sequence contains a specified element by using the default equality comparer. - /// The type of the elements of . - /// A sequence in which to locate a value. - /// The value to locate in the sequence. - /// true if the source sequence contains an element that has the specified value; otherwise, false. - public static bool Contains(this IEnumerable source, TSource value) - { - foreach (var i in source) - if (i.Equals(value)) return true; - return false; - } - - /// Returns the number of elements in a sequence. - /// The type of the elements of . - /// A sequence that contains elements to be counted. - /// The number of elements in the input sequence. - public static int Count(this IEnumerable source) - { - switch (source) - { - case null: - throw new ArgumentNullException(nameof(source)); - case ICollection c: - return c.Count; - case ICollection ngc: - return ngc.Count; - default: - var i = 0; - foreach (var e in source) i++; - return i; - } - } - - /// Returns the elements of the specified sequence or the specified value in a singleton collection if the sequence is empty. - /// The type of the elements of . - /// The sequence to return the specified value for if it is empty. - /// The value to return if the sequence is empty. This value defaults to default(TSource). - /// An that contains if source is empty; otherwise, source. - public static IEnumerable DefaultIfEmpty(this IEnumerable source, TSource defaultValue = default) - { - if (source == null) throw new ArgumentNullException(nameof(source)); - using (var e = source.GetEnumerator()) - { - if (e.MoveNext()) - { - do - { - yield return e.Current; - } while (e.MoveNext()); - } - else - { - yield return defaultValue; - } - } - } - - /// Returns distinct elements from a sequence by using the default equality comparer to compare values. - /// The type of the elements of . - /// The sequence to remove duplicate elements from. - /// An that contains distinct elements from the source sequence. - public static IEnumerable Distinct(this IEnumerable source) - { - var set = new Hashtable(); - foreach (var element in source) - if (!set.ContainsKey(element)) - { - set.Add(element, null); - yield return element; - } - } - - /// Returns the first element of a sequence. - /// The type of the elements of . - /// The to return the first element of. - /// The first element in the specified sequence. - public static TSource First(this IEnumerable source) - { - if (source == null) throw new ArgumentNullException(nameof(source)); - if (source is IList list) - { - if (list.Count > 0) return list[0]; - } - else - { - using (var e = source.GetEnumerator()) - { - if (e.MoveNext()) return e.Current; - } - } - throw new InvalidOperationException(@"No elements"); - } - - /// Returns the first element of a sequence that satisfies a specified condition. - /// The type of the elements of . - /// The to return the first element of. - /// A function to test each element for a condition. - /// The first element in the sequence that passes the test in the specified predicate function. - public static TSource First(this IEnumerable source, Func predicate) - { - if (source == null) throw new ArgumentNullException(nameof(source)); - if (predicate == null) throw new ArgumentNullException(nameof(predicate)); - foreach (var element in source) - if (predicate(element)) return element; - throw new InvalidOperationException(@"No match"); - } - - /// Returns the first element of a sequence, or a default value if the sequence contains no elements. - /// The type of the elements of . - /// The to return the first element of. - /// default( ) if is empty; otherwise, the first element in . - public static TSource FirstOrDefault(this IEnumerable source) - { - if (source == null) throw new ArgumentNullException(nameof(source)); - if (source is IList list) - { - if (list.Count > 0) return list[0]; - } - else - { - using (var e = source.GetEnumerator()) - { - if (e.MoveNext()) return e.Current; - } - } - return default; - } - - /// Returns the first element of the sequence that satisfies a condition or a default value if no such element is found. - /// The type of the elements of source. - /// An to return an element from. - /// A function to test each element for a condition. - /// default() if is empty or if no element passes the test specified by ; otherwise, the first element in that passes the test specified by . - public static TSource FirstOrDefault(this IEnumerable source, Func predicate) - { - if (source == null) throw new ArgumentNullException(nameof(source)); - if (predicate == null) throw new ArgumentNullException(nameof(predicate)); - foreach (var element in source) - if (predicate(element)) return element; - return default; - } - - /// Returns the minimum value in a generic sequence. - /// The type of the elements of source. - /// A sequence of values to determine the minimum value of. - /// The minimum value in the sequence. - public static TSource Min(this IEnumerable source) - { - if (source == null) throw new ArgumentNullException(nameof(source)); - var comparer = Comparer.Default; - var value = default(TSource); - if (value == null) - { - foreach (var x in source) - { - if (x != null && (value == null || comparer.Compare(x, value) < 0)) - value = x; - } - return value; - } - - var hasValue = false; - foreach (var x in source) - { - if (hasValue) - { - if (comparer.Compare(x, value) < 0) - value = x; - } - else - { - value = x; - hasValue = true; - } - } - if (hasValue) return value; - throw new InvalidOperationException("No elements"); - } - - /// Returns the maximum value in a generic sequence. - /// The type of the elements of source. - /// A sequence of values to determine the maximum value of. - /// The maximum value in the sequence. - public static TSource Max(this IEnumerable source) - { - if (source == null) throw new ArgumentNullException(nameof(source)); - var comparer = Comparer.Default; - var value = default(TSource); - if (value == null) { - foreach (var x in source) { - if (x != null && (value == null || comparer.Compare(x, value) > 0)) - value = x; - } - return value; - } - var hasValue = false; - foreach (var x in source) { - if (hasValue) { - if (comparer.Compare(x, value) > 0) - value = x; - } - else { - value = x; - hasValue = true; - } - } - if (hasValue) return value; - throw new InvalidOperationException("No elements"); - } - - /// Filters the elements of an based on a specified type. - /// The type to filter the elements of the sequence on. - /// The whose elements to filter. - /// An that contains elements from the input sequence of type . - public static IEnumerable OfType(this IEnumerable source) - { - if (source == null) throw new ArgumentNullException(nameof(source)); - foreach (object obj in source) - { - if (obj is TResult) yield return (TResult)obj; - } - } - - /// Sorts the elements of a sequence in ascending order according to a key. - /// The type of the elements of . - /// The type of the key returned by . - /// A sequence of values to order. - /// A function to extract a key from an element. - /// An whose elements are sorted according to a key. - public static IEnumerable OrderBy(this IEnumerable source, Func keySelector) - { - var d = new SortedDictionary(); - foreach (var item in source) - d.Add(keySelector(item), item); - return d.Values; - } - - /// Sorts the elements of a sequence in descending order. - /// The type of the elements of . - /// The type of the key returned by . - /// A sequence of values to order. - /// A function to extract a key from an element. - /// An whose elements are sorted in descending order according to a key. - public static IEnumerable OrderByDescending(this IEnumerable source, Func keySelector) - { - var d = new SortedDictionary(); - foreach (var item in source) - d.Add(keySelector(item), item); - return d.Values.Reverse(); - } - - /// Inverts the order of the elements in a sequence. - /// The type of the elements of source. - /// A sequence of values to reverse. - /// A sequence whose elements correspond to those of the input sequence in reverse order. - public static IEnumerable Reverse(this IEnumerable source) - { - if (source == null) throw new ArgumentNullException(nameof(source)); - IList items = source as IList ?? source.ToList(); - for (int i = items.Count - 1; i >= 0; i--) yield return items[i]; - } - - /// Projects each element of a sequence into a new form. - /// The type of the elements of . - /// The type of the value returned by . - /// A sequence of values to invoke a transform function on. - /// A transform function to apply to each element. - /// An whose elements are the result of invoking the transform function on each element of . - public static IEnumerable Select(this IEnumerable source, Func selector) - { - if (source == null) throw new ArgumentNullException(nameof(source)); - if (selector == null) throw new ArgumentNullException(nameof(selector)); - foreach (var i in source) - yield return selector(i); - } - - /// Projects each element of a sequence to an and flattens the resulting sequences into one sequence. - /// The type of the elements of . - /// The type of the elements of the sequence returned by . - /// A sequence of values to project. - /// A transform function to apply to each element. - /// An whose elements are the result of invoking the one-to-many transform function on each element of the input sequence. - public static IEnumerable SelectMany(this IEnumerable source, Func> selector) - { - if (source == null) throw new ArgumentNullException(nameof(source)); - if (selector == null) throw new ArgumentNullException(nameof(selector)); - foreach (TSource element in source) - { - foreach (TResult subElement in selector(element)) - { - yield return subElement; - } - } - } - - /// Returns the only element of a sequence that satisfies a specified condition, and throws an exception if more than one such element exists. - /// The type of the elements of . - /// An to return a single element from. - /// A function to test an element for a condition. - /// The single element of the input sequence that satisfies a condition. - public static TSource Single(this IEnumerable source, Func predicate) - { - if (source == null) throw new ArgumentNullException(nameof(source)); - if (predicate == null) throw new ArgumentNullException(nameof(predicate)); - var result = default(TSource); - long count = 0; - foreach (var element in source) - { - if (!predicate(element)) continue; - result = element; - checked { count++; } - } - if (count == 0) throw new InvalidOperationException(@"No matches"); - if (count != 1) throw new InvalidOperationException(@"More than one match."); - return result; - } - - /// Computes the sum of a sequence of nullable values. - /// A sequence of nullable values to calculate the sum of. - /// The sum of the values in the sequence. - public static int Sum(this IEnumerable source) - { - if (source == null) throw new ArgumentNullException(nameof(source)); - int sum = 0; - checked - { - foreach (int v in source) sum += v; - } - return sum; - } - - /// - /// Computes the sum of the sequence of nullable values that are obtained by invoking a transform function on each element of the input sequence. - /// - /// The type of the elements of . - /// A sequence of values that are used to calculate a sum. - /// A transform function to apply to each element. - /// The sum of the projected values. - public static int Sum(this IEnumerable source, Func selector) => Sum(Select(source, selector)); - - /// Returns a specified number of contiguous elements from the start of a sequence. - /// The type of the elements of source. - /// A sequence to return elements from. - /// The number of elements to return. - /// An that contains the specified number of elements from the start of the input sequence. - public static IEnumerable Take(this IEnumerable source, int count) - { - if (source == null) throw new ArgumentNullException(nameof(source)); - if (count > 0) - { - foreach (TSource element in source) - { - yield return element; - if (--count == 0) break; - } - } - } - - /// Returns elements from a sequence as long as a specified condition is true. - /// The type of the elements of source. - /// A sequence to return elements from. - /// A function to test each element for a condition. - /// An that contains the elements from the input sequence that occur before the element at which the test no longer passes. - public static IEnumerable TakeWhile(this IEnumerable source, Func predicate) - { - if (source == null) throw new ArgumentNullException(nameof(source)); - if (predicate == null) throw new ArgumentNullException(nameof(predicate)); - foreach (TSource element in source) - { - if (!predicate(element)) break; - yield return element; - } - } - - /// Creates an array from a . - /// The type of the elements of . - /// An to create an array from. - /// An array that contains the elements from the input sequence. - public static TSource[] ToArray(this IEnumerable source) => ToList(source).ToArray(); - - /// - /// Creates a from an according to a specified key selector function, a comparer, and - /// an element selector function. - /// - /// The type of the elements of . - /// The type of the key returned by . - /// The type of the value returned by . - /// An to create a from. - /// A function to extract a key from each element. - /// A transform function to produce a result element value from each element. - /// An to compare keys. - /// A that contains values of type TElement selected from the input sequence. - public static Dictionary ToDictionary(this IEnumerable source, Func keySelector, Func elementSelector, IEqualityComparer comparer) - { - if (source == null) throw new ArgumentNullException(nameof(source)); - if (keySelector == null) throw new ArgumentNullException(nameof(keySelector)); - if (elementSelector == null) throw new ArgumentNullException(nameof(elementSelector)); - var d = new Dictionary(comparer); - foreach (var element in source) d.Add(keySelector(element), elementSelector(element)); - return d; - } - - /// Creates a from an . - /// The type of the elements of . - /// An to create a from. - /// A that contains elements from the input sequence. - public static List ToList(this IEnumerable source) - { - var l = new List(); - foreach (var i in source) - l.Add(i); - return l; - } - - /// Filters a sequence of values based on a predicate. - /// The type of the elements of . - /// An to filter. - /// A function to test each element for a condition. - /// An that contains elements from the input sequence that satisfy the condition. - public static IEnumerable Where(this IEnumerable source, Func predicate) - { - if (predicate == null) throw new ArgumentNullException(nameof(predicate)); - foreach (var i in source) - if (predicate(i)) yield return i; - } - } -} -#endif \ No newline at end of file diff --git a/Core/BkwdComp/System.Collections.Generic.PreNet45.cs b/Core/BkwdComp/System.Collections.Generic.PreNet45.cs deleted file mode 100644 index aa63d6cf..00000000 --- a/Core/BkwdComp/System.Collections.Generic.PreNet45.cs +++ /dev/null @@ -1,63 +0,0 @@ -#if NET20 || NET35 || NET40 -namespace System.Collections.Generic -{ - /// Represents a strongly-typed, read-only collection of elements. - /// The type of the elements. - /// - public interface IReadOnlyCollection : IEnumerable - { - /// Gets the number of elements in the collection. - /// The number of elements in the collection. - int Count { get; } - } - - /// Represents a generic read-only collection of key/value pairs. - /// The type of keys in the read-only dictionary. - /// The type of values in the read-only dictionary. - public interface IReadOnlyDictionary : IReadOnlyCollection> - { - /// Determines whether the read-only dictionary contains an element that has the specified key. - /// The key to locate. - /// - /// if the read-only dictionary contains an element that has the specified key; otherwise, . - /// - bool ContainsKey(TKey key); - - /// Gets the value that is associated with the specified key. - /// The key to locate. - /// - /// When this method returns, the value associated with the specified key, if the key is found; otherwise, the default value for the - /// type of the parameter. This parameter is passed uninitialized. - /// - /// - /// if the object that implements the interface contains an - /// element that has the specified key; otherwise, . - /// - bool TryGetValue(TKey key, out TValue value); - - /// Gets the element that has the specified key in the read-only dictionary. - /// The key to locate. - /// The element that has the specified key in the read-only dictionary. - TValue this[TKey key] { get; } - - /// Gets an enumerable collection that contains the keys in the read-only dictionary. - /// An enumerable collection that contains the keys in the read-only dictionary. - IEnumerable Keys { get; } - - /// Gets an enumerable collection that contains the values in the read-only dictionary. - /// An enumerable collection that contains the values in the read-only dictionary. - IEnumerable Values { get; } - } - - /// Represents a read-only collection of elements that can be accessed by index. - /// The type of elements in the read-only list. - /// - public interface IReadOnlyList : IReadOnlyCollection - { - /// Gets the element at the specified index in the read-only list. - /// The element at the specified index in the read-only list. - /// The zero-based index of the element to get. - T this[int index] { get; } - } -} -#endif \ No newline at end of file diff --git a/Core/BkwdComp/System.Collections.Specialized.Net20.cs b/Core/BkwdComp/System.Collections.Specialized.Net20.cs deleted file mode 100644 index 9b1c88b0..00000000 --- a/Core/BkwdComp/System.Collections.Specialized.Net20.cs +++ /dev/null @@ -1,142 +0,0 @@ -#if (NET20) -namespace System.Collections.Specialized -{ - /// - /// Stub - /// - public interface INotifyCollectionChanged - { - /// - /// Stub - /// - event NotifyCollectionChangedEventHandler CollectionChanged; - } - - /// - /// Stub - /// - /// The sender. - /// The instance containing the event data. - public delegate void NotifyCollectionChangedEventHandler(object sender, NotifyCollectionChangedEventArgs e); - - /// - /// Stub - /// - public class NotifyCollectionChangedEventArgs : EventArgs - { - /// - /// Initializes a new instance of the class. - /// - /// The action. - /// The new items. - /// The old items. - /// The new index. - /// The old index. - internal NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction action, IList newItems, IList oldItems, int newIndex, int oldIndex) - { - Action = action; - NewItems = newItems; - NewStartingIndex = newIndex; - OldItems = oldItems; - OldStartingIndex = oldIndex; - } - - /// - /// Initializes a new instance of the class. - /// - /// The action. - public NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction action) : - this(action, null, null, -1, -1) { } - - /// - /// Initializes a new instance of the class. - /// - /// The action. - /// The item. - /// The index. - public NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction action, object item, int idx = -1) : - this(action, new object[] { item }, null, idx, -1) { } - - /// - /// Initializes a new instance of the class. - /// - /// The action. - /// The item. - /// The item2. - /// The index. - public NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction action, object item, object item2, int idx) : - this(action, new object[] { item }, new object[] { item2 }, idx, -1) { } - - /// - /// Initializes a new instance of the class. - /// - /// The action. - /// The new items. - public NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction action, IList newItems) : - this(action, newItems, null, -1, -1) { } - - /// - /// Gets the action. - /// - /// - /// The action. - /// - public NotifyCollectionChangedAction Action { get; } - /// - /// Gets the new items. - /// - /// - /// The new items. - /// - public IList NewItems { get; } - /// - /// Gets the new index of the starting. - /// - /// - /// The new index of the starting. - /// - public int NewStartingIndex { get; } - /// - /// Gets the old items. - /// - /// - /// The old items. - /// - public IList OldItems { get; } - /// - /// Gets the old index of the starting. - /// - /// - /// The old index of the starting. - /// - public int OldStartingIndex { get; } - } - - /// - /// Stub - /// - public enum NotifyCollectionChangedAction - { - /// - /// The add - /// - Add = 0, - /// - /// The move - /// - Move = 3, - /// - /// The remove - /// - Remove = 1, - /// - /// The replace - /// - Replace = 2, - /// - /// The reset - /// - Reset = 4 - } -} -#endif \ No newline at end of file diff --git a/Core/BkwdComp/Tuple.NET2.cs b/Core/BkwdComp/Tuple.NET2.cs deleted file mode 100644 index d3fd1c0b..00000000 --- a/Core/BkwdComp/Tuple.NET2.cs +++ /dev/null @@ -1,33 +0,0 @@ -#if (NET20 || NET35) - -namespace System -{ - /// Represents a 2-tuple, or pair. - /// The type of the tuple's first component. - /// The type of the tuple's second component. - [Serializable] - public class Tuple - { - private readonly T1 m_Item1; - private readonly T2 m_Item2; - - /// Initializes a new instance of the class. - /// The value of the tuple's first component. - /// The value of the tuple's second component. - public Tuple(T1 item1, T2 item2) { m_Item1 = item1; m_Item2 = item2; } - - /// Gets the value of the current object's first component. - /// The value of the current object's first component. - public T1 Item1 => m_Item1; - - /// Gets the value of the current object's second component. - /// The value of the current object's second component. - public T2 Item2 => m_Item2; - - /// Returns a that represents this instance. - /// A that represents this instance. - public override string ToString() => $"({m_Item1}, {m_Item2})"; - } -} - -#endif \ No newline at end of file diff --git a/Core/Vanara.Core.csproj b/Core/Vanara.Core.csproj index 1935c2da..fd6a8328 100644 --- a/Core/Vanara.Core.csproj +++ b/Core/Vanara.Core.csproj @@ -9,7 +9,7 @@ * Memory stream based on marshaled memory Copyright © 2017-2018 $(AssemblyName) - 2.0.1 + 2.1.0 net20;net35;net40;net45;netstandard20 Vanara.Core $(AssemblyName) @@ -73,4 +73,7 @@ CorrepsondingAction, StringListPackMethod + + + \ No newline at end of file