static void LinqAsEnumerable() { Console.WriteLine("=== " + MethodInfo.GetCurrentMethod().Name + " ==="); // Create a new Clump<T> object. var fruitClump = new Clump <string> { "apple", "passionfruit", "banana", "mango", "orange", "blueberry", "grape", "strawberry" }; // First call to Where(): // Call Clump's Where() method with a predicate. var query1 = fruitClump.Where(fruit => fruit.Contains("o")); Console.WriteLine("query1 has been created."); foreach (var f in query1) { Console.WriteLine(f); } // Second call to Where(): // First call AsEnumerable() to hide Clump's Where() method and thereby // force System.Linq.Enumerable's Where() method to be called. var query2 = fruitClump.AsEnumerable().Where(fruit => fruit.Contains("o")); // Display the output. Console.WriteLine("query2 has been created."); foreach (var f in query2) { Console.WriteLine(f); } }
public void AsEnumerable() { // Create a new Clump<T> object. Clump <string> fruitClump = new Clump <string> { "apple", "passionfruit", "banana", "mango", "orange", "blueberry", "grape", "strawberry" }; // First call to Where(): // Call Clump's Where() method with a predicate. IEnumerable <string> query1 = fruitClump.Where(fruit => fruit.Contains("o")); Assert.IsTrue(fruitClump.ClumpWhereCalled); fruitClump.ClumpWhereCalled = false; // Second call to Where(): // First call AsEnumerable() to hide Clump's Where() method and thereby // force System.Linq.Enumerable's Where() method to be called. IEnumerable <string> query2 = fruitClump.AsEnumerable().Where(fruit => fruit.Contains("o")); Assert.IsFalse(fruitClump.ClumpWhereCalled); }
public void AsEnumerableMethodTest() { Clump <string> fruitClump = new Clump <string> { "apple", "mango", "banana" }; Assert.False(fruitClump.ClumpWhereMethodCalled); fruitClump.Where(x => x.Contains("go")); Assert.True(fruitClump.ClumpWhereMethodCalled); fruitClump.ClumpWhereMethodCalled = false; fruitClump.AsEnumerable().Where(x => x.Contains("go")); Assert.False( fruitClump.ClumpWhereMethodCalled, "IEnumerable<>로 casting. 그래서 Clump:Where는 감춰진다."); }