Beispiel #1
0
        public void CovariantTest()
        {
            const int  numberInRange  = 100;
            List <int> data           = Enumerable.Range(0, numberInRange).ToList();
            string     expectedResult = string.Join(",", data);

            IRunOnceEnumerable <ChildClass> e = data.Select(s => new ChildClass(s)).OnlyRunOnce();

            // This is really a compiler time test.
            // This method will only be callable if IRunOnceEnumerable is covariant.
            // It will produce a compiler error otherwise.
            string actualResult = CovariantAction(e);

            Assert.AreEqual(expectedResult, actualResult);
        }
Beispiel #2
0
 private string CovariantAction(IRunOnceEnumerable <ParentClass> data)
 {
     return(string.Join(",", data.Select(d => d.StringData)));
 }