Skip to content

Instantly share code, notes, and snippets.

@cymen
Created June 10, 2012 05:53
Show Gist options
  • Save cymen/2904048 to your computer and use it in GitHub Desktop.
Save cymen/2904048 to your computer and use it in GitHub Desktop.
public static class MyObjectManagerExtensions
{
public static IEnumerable<selectlistitem> AsSelectList(this IEnumerable<myobject> list, int? value)
{
return (from item in list
select new SelectListItem
{
Selected = value.HasValue && item.Id == value.Value,
Text = item.Name,
Value = item.Id.ToString()
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment