1
Iterator 메서드의 인수를 사용하여 메서드 이름을 가져오고 싶습니다. 간단한 솔루션을 찾기 위해 고심하고 있습니다. 반복자는 컴파일러에 의해 생성됩니다. 결과적으로 소스 메서드 이름과 인수는 생성 된 클래스 이름에 있고 필드는 각각 (일부 마법을 사용하여 <> + _ d 기호) 필드에 있습니다.Iterator 메서드를 출력하는 방법
Visual Studio의 직접 실행 창에서 반복기 메서드를 입력 할 때 메서드 이름과 그 인수가 꽤 비슷합니다. 그들은 몇몇 사용자 정의 프린터를 사용하고 있습니까? 아니면 그렇게 할 수있는 도우미가 있습니까?
편집 :
는주요 목표는 코 루틴 비동기 호출 스택을 얻는 것입니다.
using System;
using System.Collections;
using System.Linq;
class Program
{
static IEnumerable TestB(string b)
{
yield return b;
yield return b;
}
static IEnumerable Test(string a, string b)
{
yield return a;
yield return TestB(b);
}
static void Main(string[] args)
{
var iterator = Test("foo", "bar");
// Immediate Window
// ================
// iterator
// {Program.Test}
// a: null
// b: null
// System.Collections.Generic.IEnumerator<System.Object>.Current: null
// System.Collections.IEnumerator.Current: null
Console.WriteLine(iterator);
// prints:
// Program+<Test>d__0
foreach (var field in iterator.GetType().GetFields())
Console.WriteLine(field);
// prints:
// System.String a
// System.String <>3__a
// System.String b
// System.String <>3__b
}
}
"예쁜 인쇄물"의 의미가 명확하지 않습니다. 당신은 어떤 결과를 기대 했습니까 *? –
메서드 이름과 인수를 가져 오려고합니다. – mipi
목표는 다음과 같습니다. Program.Test (a, b) – mipi