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; }
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(); }
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(); }