Created
December 6, 2012 06:49
Revisions
-
Scott Koon created this gist
Dec 6, 2012 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,25 @@ 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(); } }