Created
April 5, 2013 05:59
-
-
Save droyad/5316985 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static void ForSingleMaybe<T>(this IEnumerable<T> sequence, Action<T> action) | |
| { | |
| using(var enumerator = sequence.GetEnumerator()) | |
| { | |
| if(!enumerator.MoveNext()) | |
| return; | |
| var item = enumerator.Current; | |
| if(enumerator.MoveNext()) | |
| throw new InvalidOperationException("Sequence contains too many elements"); | |
| action(item); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment