Skip to content

Instantly share code, notes, and snippets.

@davidalpert
Created August 9, 2010 15:25
Show Gist options
  • Save davidalpert/515564 to your computer and use it in GitHub Desktop.
Save davidalpert/515564 to your computer and use it in GitHub Desktop.
ListHelpers - ToSelectItems(...)
public static IEnumerable<SelectListItem> ToSelectItems(this IEnumerable<String> items)
{
foreach (var item in items)
{
yield return new SelectListItem()
{
Text = item,
Value = item
};
}
}
public static IEnumerable<SelectListItem> ToSelectItems(this IEnumerable<String> items)
{
return items.ToSelectItems(s => s);
}
public static IEnumerable<SelectListItem> ToSelectItems(this IEnumerable<String> items, Func<string, string> buildText)
{
foreach (var item in items)
{
yield return new SelectListItem()
{
Text = buildText(item),
Value = item
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment