Esempio n. 1
0
 private IEnumerable <ICountingStrategy> ForArray()
 {
     if (values is Array)
     {
         yield return(CountingStrategy.ByLengthGetter((Array)values));
     }
 }
Esempio n. 2
0
        private IEnumerable <ICountingStrategy> ForGenericCollection()
        {
            var collection = values as ICollection;

            if (!ReferenceEquals(null, collection))
            {
                yield return(CountingStrategy.ByCountGetter(() => collection.Count));

                yield return(CountingStrategy.ByEnumeratingElements(values));
            }
        }
Esempio n. 3
0
        private IEnumerable <ICountingStrategy> ForNonGenericCollection()
        {
            foreach (Type type in values.GetType().GetInterfaces())
            {
                if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(ICollection <>))
                {
                    yield return(CountingStrategy.ByCountGetter(() => (int)type.GetProperty("Count").GetValue(values, null)));

                    yield return(CountingStrategy.ByEnumeratingElements(values));
                }
            }
        }
Esempio n. 4
0
        private IEnumerable <ICountingStrategy> ForSimpleEnumerable()
        {
            var type     = values.GetType();
            var property = type.GetProperty("Count", BindingFlags.Instance | BindingFlags.Public, null, typeof(int), EmptyArray <Type> .Instance, null);

            if (property != null)
            {
                yield return(CountingStrategy.ByReflectedCountGetter(() => (int)property.GetValue(values, null)));
            }

            yield return(CountingStrategy.ByEnumeratingElements(values));
        }