Ejemplo n.º 1
0
        public static IIterable <decimal?> SumMany(this IIterable <decimal?> source)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            var linkIterable = source as ILinkIterable <decimal?>;

            if (linkIterable != null)
            {
                return(linkIterable.Sum());
            }
            return(new LinkIterable <decimal?, decimal?>(source, Iterator.Sum(default(IIteratorLink <decimal?, decimal?>))));
        }
Ejemplo n.º 2
0
            public ILinkIterable <TResult> Sum()
            {
                Type type           = typeof(TResult);
                Type underlyingType = Nullable.GetUnderlyingType(type);

                bool     nullable;
                TypeCode typeCode;

                if (underlyingType != null)
                {
                    nullable = true;
                    typeCode = Type.GetTypeCode(underlyingType);
                }
                else
                {
                    nullable = false;
                    typeCode = Type.GetTypeCode(type);
                }

                switch (typeCode)
                {
                case TypeCode.Int32:
                    return(nullable ? (ILinkIterable <TResult>)(object) new LinkIterable <TSource, int?>(iterable, Iterator.Sum((IIteratorLink <TSource, int?>) this.link)) : (ILinkIterable <TResult>)(object) new LinkIterable <TSource, int>(iterable, Iterator.Sum((IIteratorLink <TSource, int>) this.link)));

                case TypeCode.Int64:
                    return(nullable ? (ILinkIterable <TResult>)(object) new LinkIterable <TSource, long?>(iterable, Iterator.Sum((IIteratorLink <TSource, long?>) this.link)) : (ILinkIterable <TResult>)(object) new LinkIterable <TSource, long>(iterable, Iterator.Sum((IIteratorLink <TSource, long>) this.link)));

                case TypeCode.Single:
                    return(nullable ? (ILinkIterable <TResult>)(object) new LinkIterable <TSource, float?>(iterable, Iterator.Sum((IIteratorLink <TSource, float?>) this.link)) : (ILinkIterable <TResult>)(object) new LinkIterable <TSource, float>(iterable, Iterator.Sum((IIteratorLink <TSource, float>) this.link)));

                case TypeCode.Double:
                    return(nullable ? (ILinkIterable <TResult>)(object) new LinkIterable <TSource, double?>(iterable, Iterator.Sum((IIteratorLink <TSource, double?>) this.link)) : (ILinkIterable <TResult>)(object) new LinkIterable <TSource, double>(iterable, Iterator.Sum((IIteratorLink <TSource, double>) this.link)));

                case TypeCode.Decimal:
                    return(nullable ? (ILinkIterable <TResult>)(object) new LinkIterable <TSource, decimal?>(iterable, Iterator.Sum((IIteratorLink <TSource, decimal?>) this.link)) : (ILinkIterable <TResult>)(object) new LinkIterable <TSource, decimal>(iterable, Iterator.Sum((IIteratorLink <TSource, decimal>) this.link)));

                default:
                    throw new NotImplementedException();
                }
            }