Skip to content

Instantly share code, notes, and snippets.

@tpetrina
Created September 13, 2012 12:48
Show Gist options
  • Save tpetrina/3714097 to your computer and use it in GitHub Desktop.
Save tpetrina/3714097 to your computer and use it in GitHub Desktop.
Similar to SelectMany method, only projects members
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;
}
}
}
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