Skip to content

Instantly share code, notes, and snippets.

@rbazinet
Created February 27, 2010 01:43
Show Gist options
  • Save rbazinet/316393 to your computer and use it in GitHub Desktop.
Save rbazinet/316393 to your computer and use it in GitHub Desktop.
public static class ListExtensions {
public static IEnumerable<T> ForEach<T>(this IEnumerable<T> collection, Action<T> action) {
foreach (var item in collection) action(item);
return collection;
}
public static SelectList ToSelectList<T>(this IEnumerable<T> collection) {
return new SelectList(collection, "Key", "Value");
}
public static SelectList ToSelectList<T>(this IEnumerable<T> collection, string selectedValue) {
return new SelectList(collection, "Key", "Value", selectedValue);
}
public static SelectList ToSelectList<T>(this IEnumerable<T> collection,
string dataValueField, string dataTextField) {
return new SelectList(collection, dataValueField, dataTextField);
}
public static SelectList ToSelectList<T>(this IEnumerable<T> collection,
string dataValueField, string dataTextField, string selectedValue) {
return new SelectList(collection, dataValueField, dataTextField, selectedValue);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment