I want to get the method name with its arguments of Iterator Method and I am struggling to find a simple solution. Iterators are generated by a compiler as a result the source method name and it's arguments are now in a generated class name and it's fields respectively (with some magic <>+_d symbols).
In Immediate window of Visual Studio when I enter the iterator method I get the method name and it's arguments in a pretty way. Are they using some custom printers or maybe there is some helpers to do that?
Edit:
The main goal is to get the coroutine async call stack.
Program.Test(a, b)
Program.TestB(b)
Here is an example:
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
}
}