Skip to content

Instantly share code, notes, and snippets.

@kolosovpetro
Created March 20, 2021 10:14
Show Gist options
  • Save kolosovpetro/a1005016c0dbd8619e7303df1fc2a292 to your computer and use it in GitHub Desktop.
Save kolosovpetro/a1005016c0dbd8619e7303df1fc2a292 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
public class C {
public void M() {
var col = Collection().ToList();
foreach(var item in col)
{
Console.WriteLine(item);
}
}
public IEnumerable<string> Collection()
{
yield return "one";
yield return "two";
yield return "three";
}
}
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
public class C
{
[CompilerGenerated]
private sealed class <Collection>d__1 : IEnumerable<string>, IEnumerable, IEnumerator<string>, IDisposable, IEnumerator
{
private int <>1__state;
private string <>2__current;
private int <>l__initialThreadId;
public C <>4__this;
string IEnumerator<string>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <Collection>d__1(int <>1__state)
{
this.<>1__state = <>1__state;
<>l__initialThreadId = Environment.CurrentManagedThreadId;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
}
private bool MoveNext()
{
switch (<>1__state)
{
default:
return false;
case 0:
<>1__state = -1;
<>2__current = "one";
<>1__state = 1;
return true;
case 1:
<>1__state = -1;
<>2__current = "two";
<>1__state = 2;
return true;
case 2:
<>1__state = -1;
<>2__current = "three";
<>1__state = 3;
return true;
case 3:
<>1__state = -1;
return false;
}
}
bool IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
[DebuggerHidden]
IEnumerator<string> IEnumerable<string>.GetEnumerator()
{
<Collection>d__1 <Collection>d__;
if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId)
{
<>1__state = 0;
<Collection>d__ = this;
}
else
{
<Collection>d__ = new <Collection>d__1(0);
<Collection>d__.<>4__this = <>4__this;
}
return <Collection>d__;
}
[DebuggerHidden]
IEnumerator IEnumerable.GetEnumerator()
{
return ((IEnumerable<string>)this).GetEnumerator();
}
}
public void M()
{
List<string> list = Enumerable.ToList(Collection());
List<string>.Enumerator enumerator = list.GetEnumerator();
try
{
while (enumerator.MoveNext())
{
string current = enumerator.Current;
Console.WriteLine(current);
}
}
finally
{
((IDisposable)enumerator).Dispose();
}
}
[IteratorStateMachine(typeof(<Collection>d__1))]
public IEnumerable<string> Collection()
{
<Collection>d__1 <Collection>d__ = new <Collection>d__1(-2);
<Collection>d__.<>4__this = this;
return <Collection>d__;
}
}
{
"version": 1,
"target": "C#",
"mode": "Debug"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment