So I got this crazy idea I could make make something cool work. I got tired of new selectlist(item, "blah", "blahblah") so I started writing an extension method (trying to get it more strongly typed) something like this ...
var selectList = projects.ToSelectList(p =>p.ProjectID, p =>p.ProjectName);
the extension method goes a little like this
public static SelectList ToSelectList<T>(this IEnumerable<T> item,
Expression<Func<T, string>> textName,
Expression<Func<T, string>> valueProperty)
{
//do cool stuff
return new SelectList(items, dataTextField, dataValueField);
}
What I need to get to is the reflection properties so I can grab the value and grab the name. Any ideas onhow I can do that? Any thoughts on doing this more better/easier? I've done this before but for the life of me I can't remember how I did it.
Edit this needed some clarification. I copied some code that was in-flight and not refined, so I've updated that code to reflect the more correct criteria.