Created
December 6, 2012 06:49
-
-
Save skoon/4222288 to your computer and use it in GitHub Desktop.
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 class Extensions | |
{ | |
public static IEnumerable<DropDownFormat> ToDropDownFormat<T>(this IList<T> list, | |
Expression<Func<T, int>> idColumn, | |
Expression<Func<T, string>> textColumn) | |
{ | |
List<DropDownFormat> retList = new List<DropDownFormat>(); | |
var idMemberExp = (MemberExpression)idColumn.Body; | |
var textMemberExp = (MemberExpression)textColumn.Body; | |
var idName = idMemberExp.Member.Name; | |
var textName = textMemberExp.Member.Name; | |
foreach (T o in list) | |
{ | |
var typeOfList = typeof(T); | |
var id = (int)typeOfList.GetProperty(idName).GetValue(o, null); | |
var text = (string)typeOfList.GetProperty(textName).GetValue(o, null); | |
var ddf = new DropDownFormat() { Id = id, Text = text }; | |
retList.Add(ddf); | |
} | |
return retList.ToList(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment