コード例 #1
0
 public static bool TryGet <TValue, TArgument>(this IEnumerable <TValue> collection, TArgument argument, CollectionPredicate <TValue, TArgument> predicate, out TValue result)
 {
     return(CollectionsUtility.TryGet(collection, argument, predicate, out result));
 }
コード例 #2
0
 public static TValue Get <TValue, TArgument>(this IEnumerable <TValue> collection, TArgument argument, CollectionPredicate <TValue, TArgument> predicate)
 {
     return(CollectionsUtility.TryGet(collection, argument, predicate, out TValue result) ? result : throw new CollectionValueNotFoundByArgumentException(argument));
 }
        public static bool TryGet <TKey, TValue, TArgument>(this Dictionary <TKey, TValue> .ValueCollection collection, TArgument argument, CollectionPredicate <TValue, TArgument> predicate, out TValue result)
        {
            if (collection == null)
            {
                throw new ArgumentNullException(nameof(collection));
            }

            return(CollectionsUtility.TryGet(collection.GetEnumerator(), argument, predicate, out result));
        }
        public static TKey Get <TKey, TValue, TArgument>(this Dictionary <TKey, TValue> .KeyCollection collection, TArgument argument, CollectionPredicate <TKey, TArgument> predicate)
        {
            if (collection == null)
            {
                throw new ArgumentNullException(nameof(collection));
            }

            return(CollectionsUtility.TryGet(collection.GetEnumerator(), argument, predicate, out TKey result) ? result : throw new CollectionValueNotFoundByArgumentException(argument));
        }
コード例 #5
0
 /// <summary>Comparer compares all object as
 ///     <see cref="object.Equals(object)"/> by default.
 ///     Choose objects you would like to treat as collections</summary>
 public DeepComparerBuilder GoDeepFor(CollectionPredicate func)
 {
     _rulesContainer.TreatAsCollection(func);
     return(this);
 }
コード例 #6
0
 public void TreatAsCollection(CollectionPredicate func)
 {
     _byFunc.Add(x => func(x) ?? TreatObjectAs.Simple);
 }
コード例 #7
0
        public static bool TryGet <TValue, TArgument, TCollection>(TCollection collection, TArgument argument, CollectionPredicate <TValue, TArgument> predicate, CollectionIndexer <TValue, TCollection> indexer, int count, out TValue result)
        {
            if (predicate == null)
            {
                throw new ArgumentNullException(nameof(predicate));
            }
            if (indexer == null)
            {
                throw new ArgumentNullException(nameof(indexer));
            }

            for (int i = 0; i < count; i++)
            {
                TValue element = indexer(collection, i);

                if (predicate(element, argument))
                {
                    result = element;
                    return(true);
                }
            }

            result = default;
            return(false);
        }
コード例 #8
0
        public static bool TryGet <TValue, TArgument, TEnumerator>(TEnumerator enumerator, TArgument argument, CollectionPredicate <TValue, TArgument> predicate, out TValue result) where TEnumerator : IEnumerator <TValue>
        {
            if (predicate == null)
            {
                throw new ArgumentNullException(nameof(predicate));
            }

            while (enumerator.MoveNext())
            {
                TValue element = enumerator.Current;

                if (predicate(element, argument))
                {
                    result = element;
                    return(true);
                }
            }

            result = default;
            return(false);
        }
コード例 #9
0
        public static bool TryGet <TValue, TArgument>(IEnumerable <TValue> collection, TArgument argument, CollectionPredicate <TValue, TArgument> predicate, out TValue result)
        {
            if (collection == null)
            {
                throw new ArgumentNullException(nameof(collection));
            }

            return(TryGet(collection.GetEnumerator(), argument, predicate, out result));
        }
        public static TValue Get <TValue, TArgument>(this List <TValue> collection, TArgument argument, CollectionPredicate <TValue, TArgument> predicate)
        {
            if (collection == null)
            {
                throw new ArgumentNullException(nameof(collection));
            }

            return(CollectionsUtility.TryGet(collection, argument, predicate, (list, index) => list[index], collection.Count, out TValue result) ? result : throw new CollectionValueNotFoundByArgumentException(argument));
        }
        public static bool TryGet <TValue, TArgument>(this IList <TValue> collection, TArgument argument, CollectionPredicate <TValue, TArgument> predicate, out TValue result)
        {
            if (collection == null)
            {
                throw new ArgumentNullException(nameof(collection));
            }

            return(CollectionsUtility.TryGet(collection, argument, predicate, (list, index) => list[index], collection.Count, out result));
        }