Create a gist now

Instantly share code, notes, and snippets.

@sehe /test.cs
Created Nov 21, 2011

monodis for enumerables
using System.Collections.Generic;
public class Program
{
public static IEnumerable<int> UsingYield()
{
yield return 42;
}
public static IEnumerable<int> ReturningArray()
{
return new []{ 42 };
}
public static void Main(string[] args) {}
}
.assembly extern mscorlib
{
.ver 4:0:0:0
.publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4..
}
.assembly 'test'
{
.custom instance void class [mscorlib]System.Runtime.CompilerServices.RuntimeCompatibilityAttribute::'.ctor'() = (
01 00 01 00 54 02 16 57 72 61 70 4E 6F 6E 45 78 // ....T..WrapNonEx
63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 ) // ceptionThrows.
.hash algorithm 0x00008004
.ver 0:0:0:0
}
.module test.exe // GUID = {999C8256-8C09-4C29-ADFC-CCE578327698}
.class public auto ansi beforefieldinit Program
extends [mscorlib]System.Object
{
// method line 1
.method public hidebysig specialname rtspecialname
instance default void '.ctor' () cil managed
{
// Method begins at RVA 0x20ec
// Code size 7 (0x7)
.maxstack 8
IL_0000: ldarg.0
IL_0001: call instance void object::'.ctor'()
IL_0006: ret
} // end of method Program::.ctor
// method line 2
.method public static hidebysig
default class [mscorlib]System.Collections.Generic.IEnumerable`1<int32> UsingYield () cil managed
{
.custom instance void class [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::'.ctor'() = (01 00 00 00 ) // ....
// Method begins at RVA 0x20f4
// Code size 16 (0x10)
.maxstack 3
.locals init (
class Program/'<UsingYield>c__Iterator0' V_0)
IL_0000: newobj instance void class Program/'<UsingYield>c__Iterator0'::'.ctor'()
IL_0005: stloc.0
IL_0006: ldloc.0
IL_0007: dup
IL_0008: ldc.i4.s 0xfffffffe
IL_000a: stfld int32 Program/'<UsingYield>c__Iterator0'::$PC
IL_000f: ret
} // end of method Program::UsingYield
// method line 3
.method public static hidebysig
default class [mscorlib]System.Collections.Generic.IEnumerable`1<int32> ReturningArray () cil managed
{
// Method begins at RVA 0x2110
// Code size 12 (0xc)
.maxstack 8
IL_0000: ldc.i4.1
IL_0001: newarr [mscorlib]System.Int32
IL_0006: dup
IL_0007: ldc.i4.0
IL_0008: ldc.i4.s 0x2a
IL_000a: stelem.i4
IL_000b: ret
} // end of method Program::ReturningArray
// method line 4
.method public static hidebysig
default void Main (string[] args) cil managed
{
// Method begins at RVA 0x2120
.entrypoint
// Code size 1 (0x1)
.maxstack 8
IL_0000: ret
} // end of method Program::Main
.class nested private auto ansi sealed beforefieldinit '<UsingYield>c__Iterator0'
extends [mscorlib]System.Object
implements class [mscorlib]System.Collections.Generic.IEnumerable`1<int32>, class [mscorlib]System.Collections.Generic.IEnumerator`1<int32>, [mscorlib]System.Collections.IEnumerable, [mscorlib]System.Collections.IEnumerator, [mscorlib]System.IDisposable {
.custom instance void class [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::'.ctor'() = (01 00 00 00 ) // ....
.field assembly int32 $PC
.field assembly int32 $current
// method line 5
.method public hidebysig specialname rtspecialname
instance default void '.ctor' () cil managed
{
// Method begins at RVA 0x2124
// Code size 7 (0x7)
.maxstack 8
IL_0000: ldarg.0
IL_0001: call instance void object::'.ctor'()
IL_0006: ret
} // end of method <UsingYield>c__Iterator0::.ctor
// method line 6
.method private final virtual hidebysig newslot specialname
instance default int32 'System.Collections.Generic.IEnumerator<int>.get_Current' () cil managed
{
.custom instance void class [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::'.ctor'() = (01 00 00 00 ) // ....
// Method begins at RVA 0x212c
.override method instance !0 class [mscorlib]System.Collections.Generic.IEnumerator`1<int32>::get_Current()
// Code size 7 (0x7)
.maxstack 8
IL_0000: ldarg.0
IL_0001: ldfld int32 Program/'<UsingYield>c__Iterator0'::$current
IL_0006: ret
} // end of method <UsingYield>c__Iterator0::System.Collections.Generic.IEnumerator<int>.get_Current
// method line 7
.method private final virtual hidebysig newslot specialname
instance default object System.Collections.IEnumerator.get_Current () cil managed
{
.custom instance void class [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::'.ctor'() = (01 00 00 00 ) // ....
// Method begins at RVA 0x2134
.override class [mscorlib]System.Collections.IEnumerator::get_Current
// Code size 12 (0xc)
.maxstack 8
IL_0000: ldarg.0
IL_0001: ldfld int32 Program/'<UsingYield>c__Iterator0'::$current
IL_0006: box [mscorlib]System.Int32
IL_000b: ret
} // end of method <UsingYield>c__Iterator0::System.Collections.IEnumerator.get_Current
// method line 8
.method private final virtual hidebysig newslot
instance default class [mscorlib]System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator () cil managed
{
// Method begins at RVA 0x2144
.override class [mscorlib]System.Collections.IEnumerable::GetEnumerator
// Code size 7 (0x7)
.maxstack 8
IL_0000: ldarg.0
IL_0001: call instance class [mscorlib]System.Collections.Generic.IEnumerator`1<int32> class Program/'<UsingYield>c__Iterator0'::'System.Collections.Generic.IEnumerable<int>.GetEnumerator'()
IL_0006: ret
} // end of method <UsingYield>c__Iterator0::System.Collections.IEnumerable.GetEnumerator
// method line 9
.method private final virtual hidebysig newslot
instance default class [mscorlib]System.Collections.Generic.IEnumerator`1<int32> 'System.Collections.Generic.IEnumerable<int>.GetEnumerator' () cil managed
{
.custom instance void class [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::'.ctor'() = (01 00 00 00 ) // ....
// Method begins at RVA 0x214c
.override method instance class [mscorlib]System.Collections.Generic.IEnumerator`1<!0> class [mscorlib]System.Collections.Generic.IEnumerable`1<int32>::GetEnumerator()
// Code size 26 (0x1a)
.maxstack 8
IL_0000: ldarg.0
IL_0001: ldflda int32 Program/'<UsingYield>c__Iterator0'::$PC
IL_0006: ldc.i4.0
IL_0007: ldc.i4.s 0xfffffffe
IL_0009: call int32 class [mscorlib]System.Threading.Interlocked::CompareExchange([out] int32&, int32, int32)
IL_000e: ldc.i4.s 0xfffffffe
IL_0010: bne.un.s IL_0014
IL_0012: ldarg.0
IL_0013: ret
IL_0014: newobj instance void class Program/'<UsingYield>c__Iterator0'::'.ctor'()
IL_0019: ret
} // end of method <UsingYield>c__Iterator0::System.Collections.Generic.IEnumerable<int>.GetEnumerator
// method line 10
.method public final virtual hidebysig newslot
instance default bool MoveNext () cil managed
{
// Method begins at RVA 0x2168
// Code size 64 (0x40)
.maxstack 2
.locals init (
unsigned int32 V_0)
IL_0000: ldarg.0
IL_0001: ldfld int32 Program/'<UsingYield>c__Iterator0'::$PC
IL_0006: stloc.0
IL_0007: ldarg.0
IL_0008: ldc.i4.m1
IL_0009: stfld int32 Program/'<UsingYield>c__Iterator0'::$PC
IL_000e: ldloc.0
IL_000f: switch (
IL_0021,
IL_0035)
IL_001c: br IL_003c
IL_0021: ldarg.0
IL_0022: ldc.i4.s 0x2a
IL_0024: stfld int32 Program/'<UsingYield>c__Iterator0'::$current
IL_0029: ldarg.0
IL_002a: ldc.i4.1
IL_002b: stfld int32 Program/'<UsingYield>c__Iterator0'::$PC
IL_0030: br IL_003e
IL_0035: ldarg.0
IL_0036: ldc.i4.m1
IL_0037: stfld int32 Program/'<UsingYield>c__Iterator0'::$PC
IL_003c: ldc.i4.0
IL_003d: ret
IL_003e: ldc.i4.1
IL_003f: ret
} // end of method <UsingYield>c__Iterator0::MoveNext
// method line 11
.method public final virtual hidebysig newslot
instance default void Dispose () cil managed
{
.custom instance void class [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::'.ctor'() = (01 00 00 00 ) // ....
// Method begins at RVA 0x21b4
// Code size 8 (0x8)
.maxstack 8
IL_0000: ldarg.0
IL_0001: ldc.i4.m1
IL_0002: stfld int32 Program/'<UsingYield>c__Iterator0'::$PC
IL_0007: ret
} // end of method <UsingYield>c__Iterator0::Dispose
// method line 12
.method public final virtual hidebysig newslot
instance default void Reset () cil managed
{
.custom instance void class [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::'.ctor'() = (01 00 00 00 ) // ....
// Method begins at RVA 0x21c0
// Code size 6 (0x6)
.maxstack 8
IL_0000: newobj instance void class [mscorlib]System.NotSupportedException::'.ctor'()
IL_0005: throw
} // end of method <UsingYield>c__Iterator0::Reset
.property instance int32 'System.Collections.Generic.IEnumerator<int>.Current' ()
{
.get instance default int32 Program/'<UsingYield>c__Iterator0'::'System.Collections.Generic.IEnumerator<int>.get_Current' ()
}
.property instance object System.Collections.IEnumerator.Current ()
{
.get instance default object Program/'<UsingYield>c__Iterator0'::System.Collections.IEnumerator.get_Current ()
}
} // end of class <UsingYield>c__Iterator0
} // end of class Program
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment