Created
September 13, 2012 12:48
-
-
Save tpetrina/3714097 to your computer and use it in GitHub Desktop.
Similar to SelectMany method, only projects members
This file contains 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 IEnumerable<U> SelectProjections<T, U>(this IEnumerable<T> @this, params Func<T, U>[] projections) | |
{ | |
if (@this == null) | |
throw new NullReferenceException(); | |
if (projections == null || !projections.Any()) | |
yield break; | |
foreach (var item in @this) | |
{ | |
foreach (var projection in projections) | |
{ | |
var projected = projection(item); | |
if (projected != null) | |
yield return projected; | |
} | |
} | |
} |
This file contains 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
foreach (var item in persons.SelectProjections(person => person.FirstName, person => person.LastName) | |
; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment