public static int Count <T>(this System.Collections.Generic.IEnumerable <T> e, System.Predicate <T> m = null)
        {
            if (e.IsNull())
            {
                throw new System.NullReferenceException();
            }
            var result = 0;
            var list   = new System.Collections.Generic.List <T>(e);

            if (m.IsNull())
            {
                result = list.Count;
            }
            else
            {
                for (var i = 0; i < list.Count; i++)
                {
                    if (m.Invoke(list[i]))
                    {
                        result++;
                    }
                }
            }
            list.Clear();
            return(result);
        }
Esempio n. 2
0
 public int FindIndex(System.Predicate <T> match)
 {
     if (match.IsNull())
     {
         throw new System.NullReferenceException();
     }
     return(System.Array.FindIndex(array, match));
 }
Esempio n. 3
0
 public WrappedArray <T> FindAll(System.Predicate <T> match)
 {
     if (match.IsNull())
     {
         throw new System.NullReferenceException();
     }
     return(new WrappedArray <T>(System.Array.FindAll(array, match)));
 }
 public static int FindIndex <T>(this T[] a, System.Predicate <T> m)
 {
     if (a.IsNull())
     {
         throw new System.NullReferenceException();
     }
     if (m.IsNull())
     {
         throw new System.NullReferenceException();
     }
     return(System.Array.FindIndex(a, m));
 }
 public static bool Exists <T>(this T[] a, System.Predicate <T> m) where T : class
 {
     if (a.IsNull())
     {
         throw new System.NullReferenceException();
     }
     if (m.IsNull())
     {
         throw new System.NullReferenceException();
     }
     return(!System.Array.Find(a, m).IsNull());
 }
 public static bool Any <T>(this T[] a, System.Predicate <T> m)
 {
     if (!a.IsNull() && !m.IsNull())
     {
         for (var i = 0; i < a.Length; i++)
         {
             if (m.Invoke(a[i]))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Esempio n. 7
0
 public bool Exists(System.Predicate <T> match)
 {
     if (match.IsNull())
     {
         throw new System.NullReferenceException();
     }
     for (var i = 0; i < array.Length; i++)
     {
         if (match.Invoke(array[i]))
         {
             return(true);
         }
     }
     return(false);
 }
 public static void DoFor <T>(this T[] a, System.Predicate <T> m, System.Action <T> action, bool forwardOrder = true)
 {
     if (!a.IsNull() && !action.IsNull() && !m.IsNull())
     {
         var start  = forwardOrder ? 0 : (a.Length - 1);
         var offset = forwardOrder ? 1 : -1;
         for (var i = start; (i >= 0) && (i < a.Length); i += offset)
         {
             if (m.Invoke(a[i]))
             {
                 action.Invoke(a[i]);
             }
         }
     }
 }
Esempio n. 9
0
        public int RemoveAll(System.Predicate <T> match)
        {
            if (match.IsNull())
            {
                throw new System.NullReferenceException();
            }
            var result = 0;

            for (var i = 0; i < array.Length; i++)
            {
                if (match.Invoke(array[i]))
                {
                    RemoveAt(i);
                    result++;
                    i--;
                }
            }
            return(result);
        }
 public static void RemoveAll <T>(ref T[] a, System.Predicate <T> m)
 {
     if (a.IsNull())
     {
         throw new System.NullReferenceException();
     }
     if (m.IsNull())
     {
         throw new System.NullReferenceException();
     }
     for (var i = 0; i < a.Length; i++)
     {
         if (m.Invoke(a[i]))
         {
             RemoveAt(ref a, i);
             i--;
         }
     }
 }
        public static TOutput[] FindAndConvert <TInput, TOutput>(this System.Collections.Generic.IEnumerable <TInput> e, System.Predicate <TInput> m, System.Converter <TInput, TOutput> c)
        {
            if (e.IsNull())
            {
                throw new System.NullReferenceException();
            }
            if (m.IsNull())
            {
                throw new System.NullReferenceException();
            }
            var list      = new System.Collections.Generic.List <TInput>(e);
            var finded    = list.FindAll(m);
            var converted = finded.ConvertAll(c);
            var result    = converted.ToArray();

            list.Clear();
            finded.Clear();
            converted.Clear();
            return(result);
        }