[Mono-dev] Extract method name from IEnumerator

Marek Safar marek.safar at seznam.cz
Sun Oct 5 04:57:04 EDT 2008


Hello Joachim,
>>  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 summarized it nicely, you can use name inside <.> as original method 
name, there is couple of issue with it though.
It may change in the future and it ignores generic method and method 
overloads. Therefore if you need better name mapping you have to use our 
debug symbol file.

Marek





More information about the Mono-devel-list mailing list