Created
August 9, 2010 15:25
-
-
Save davidalpert/515564 to your computer and use it in GitHub Desktop.
ListHelpers - ToSelectItems(...)
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<SelectListItem> ToSelectItems(this IEnumerable<String> items) | |
{ | |
foreach (var item in items) | |
{ | |
yield return new SelectListItem() | |
{ | |
Text = item, | |
Value = item | |
}; | |
} | |
} |
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<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