이 간단한 콘솔 응용 프로그램을 사용하여 표시된 줄에 중단 점을 넣고 디버거를 실행 한 후 첫 번째 중단 점에서 (F11) 단계를 누르십시오. 두 번째 중단 점이 없어야합니다. Otherwsie가 시각 스튜디오 설정/확장 일을 망칠 수도 있습니다.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
namespace tmp {
class Program {
static void Main(string[] args) {
IEnumerable<Type> types = typeof(System.IO.IOException).GetHierarchy(typeof(System.Exception)); //break point here
int i = 0;
}
}
static class Ext {
//[DebuggerStepThrough]
//[DebuggerNonUserCode]
//[DebuggerStepperBoundary]
public static IEnumerable<Type> GetHierarchy(this Type type, Type limit) {
if (type == null) { //break point here
throw new Exception();
}
do {
yield return type;
if (type == limit) {
yield break;
}
} while ((type = type.BaseType) != null);
}
[DebuggerStepThrough]
public static IEnumerable<Type> GetHierarchy2(this Type type, Type limit) {
if (type == null) { //break point here
throw new Exception();
}
IList<Type> types = new List<Type>();
do {
types.Add(type);
if (type == limit) {
break;
}
} while ((type = type.BaseType) != null);
return types;
}
}
}
EDIT 사실 내가 그것을 yield 문 함께 할 수있는 뭔가가 생각합니다. 목록 (GetHierarchy2)을 빌드하려고하면 DebuggerStepThrough 특성에 아무런 문제가 없습니다.
그것은 확실히 그런 식으로 보입니다. 나는 솔직히 내가 이것을 더 일찍 알지 못한다는 것에 놀랐다. 내가 원하는 것을 얻을 수있는 다른 방법은 IEnumerable/IEnumerator 클래스를 명시 적으로 구현하는 것입니다.이 클래스는 성가신 일이지만 전체적으로 가치가있을 수 있습니다. –