Bu basit konsol uygulamasını deneyin, belirtilen satırlara kesme noktaları koyun, hata ayıklayıcıyı çalıştırın ve ilk kesme noktasında (F11) adımına basın. İkinci mola noktasını kaçırmalı. Otherwsie, bir şeyler yapabilmeniz için bir görsel stüdyo ayarı/uzantısı olabilir.
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;
}
}
}
DÜZENLEME Aslında ben verim deyimi ile ilgisi olduğunu düşünüyorum. Bir liste (GetHierarchy2) oluşturmayı denerseniz, DebuggerStepThrough özniteliği
Kesinlikle öyle görünüyor. Bunu daha önce fark etmediğime çok şaşırdım. İstediğim şeyi alabilmem için tek yolu, biraz rahatsızlık veren IEnumerable/IEnumerator sınıflarını açık bir şekilde uygulamaktır ama bütün bunlar buna değer olabilir. –