Beispiel #1
0
        public Samples(GetCount getCount, SampleIndexer sampleIndexer, IEnumerator enumerator)
        {
            if (getCount == null)
            {
                throw new ArgumentNullException("getCount");
            }
            if (sampleIndexer == null)
            {
                throw new ArgumentNullException("sampleIndexer");
            }
            if (enumerator == null)
            {
                throw new ArgumentNullException("enumerator");
            }

            var inTypeName = typeof(T).FullName;

            if (!typeCheck.IsMatch(inTypeName))
            {
                throw new Exception("T can only be of type: byte, sbyte, short, ushort, int, uint, long, ulong, float or double.");
            }

            this.getCount      = getCount;
            this.sampleIndexer = sampleIndexer;
            sampleEnumerator   = enumerator;
        }
Beispiel #2
0
        public Samples(IList <T> samples)
        {
            if (samples == null)
            {
                throw new ArgumentNullException("samples");
            }

            var inTypeName = typeof(T).FullName;

            if (!typeCheck.IsMatch(inTypeName))
            {
                throw new Exception("T can only be of type: byte, sbyte, short, ushort, int, uint, long, ulong, float or double.");
            }

            getCount         = () => samples.Count;
            sampleIndexer    = i => samples[i];
            sampleEnumerator = samples.GetEnumerator();
        }
Beispiel #3
0
        public Samples(IEnumerable <T> samples)
        {
            if (samples == null)
            {
                throw new ArgumentNullException("samples");
            }

            var inTypeName = typeof(T).FullName;

            if (!typeCheck.IsMatch(inTypeName))
            {
                throw new Exception("T can only be of type: byte, sbyte, short, ushort, int, uint, long, ulong, float or double.");
            }

            var count = 0;

            using (var enumerator = samples.GetEnumerator()) { while (enumerator.MoveNext())
                                                               {
                                                                   count++;
                                                               }
            }

            getCount      = () => count;
            sampleIndexer = i =>
            {
                var curInd = 0;
                foreach (var sam in samples)
                {
                    if (i == curInd)
                    {
                        return(sam);
                    }
                    curInd++;
                }

                throw new IndexOutOfRangeException();
            };
            sampleEnumerator = samples.GetEnumerator();
        }