Skip to content

Instantly share code, notes, and snippets.

@Salada
Created March 16, 2015 15:49
Show Gist options
  • Save Salada/6e00ef41e2d9810cb5e0 to your computer and use it in GitHub Desktop.
Save Salada/6e00ef41e2d9810cb5e0 to your computer and use it in GitHub Desktop.
public static class AotSafeExtensions
{
// こんなメソッドを用意しておくと
public static IEnumerable<T> AsSafeEnumerable<T>(this IEnumerable<T> source)
{
var e = ((IEnumerable)source).GetEnumerator();
using (e as IDisposable)
{
while (e.MoveNext())
{
yield return (T)e.Current;
}
}
}
}
@Salada
Copy link
Author

Salada commented Mar 16, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment