[Mono-dev] Extract method name from IEnumerator

Jb Evain jb at nurv.fr
Sat Oct 4 09:35:59 EDT 2008


Hey Joachim,

On 10/4/08, Joachim Ante <joe at unity3d.com> wrote:
>  Is there any way to extract the method name from an IEnumerator
>  object when using iterators?
>
>  Our users do this:
>
>  IEnumerator MyMethod ()
>  {
>         yield return 0;
>         ....
>  }
>
>  StartCoroutine(MyMethod ());
>
>  StartCoroutine passes the IEnumerator down to c code and schedules
>  MoveNext from C code.
>
>
>
>  We use this kind of setup a lot for game code. This all works great,
>  the problem is profiling.
>
>  When profiling the method name that shows up is always MoveNext. I
>  would like to replace MoveNext with the actual method name.

The method's name is always MoveNext to conform to
System.Collections.IEnumerator, but the declaring type of the method
will be named after the original method.

For example:

class Test {
	static IEnumerable<int> Foo ()
	{
		yield return 42;
	}
}

The enumerator's type will be named `<Foo>c__IteratorN`. The issue is
that this name can probably be changed as will by gmcs, but it looks
like you can get the method's original name from its generated type
name.

-- 
Jb Evain  <jb at nurv.fr>


More information about the Mono-devel-list mailing list