比方说,你写了下面的代码自定义枚举:Visual Studio如何评估IEnumerable而不破入其IEnumerator <T>的MoveNext?
public class School : IEnumerable<Student>
然后在客户端代码,你这样做:
static void Main(string[] args)
{
var school = CreateSchoolWithStudents();
var query = from student in school
where student.Name.StartsWith("S")
select student;
Debugger.Break();
}
private static School CreateSchoolWithStudents()
{
return new School
{
new Student { Name = "Sathyaish" },
new Student { Name = "John" },
new Student { Name = "Carol" },
new Student { Name = "Peter" }
};
}
然后,设置在MoveNext
方法的突破点执行你的StudentEnumerator
类。
然后,当你运行代码,构建查询/ IEnumerable的在这种情况下,后中断调试,并展开在图片中Results View
如下图所示,如何Visual Studio的评估没有闯入其枚举的MoveNext
的顺序?
我一直对此很好奇。
查找FuncEval。不错的功能有很多警告。见http://blogs.msdn.com/b/jmstall/archive/2005/03/23/400794.aspx –
太棒了。请添加此作为答案。我会将其标记为正确的。 –