I'm writing a wrapper for the WinForms ComboBox control that will let me populate the dropdown with a List<T>, and has a Selected property that returns an item of type T (or null if nothing selected).
Rather than having a Selected property, I'd like it to be named based on the generic type automatically. For example:
- MyDropDownList<User> would have a SelectedUser property
- MyDropDownList<Department> would have a SelectedDepartment property
- MyDropDownList<State> would have a SelectedState property
With LINQ, I can create anonymous types during grouping, like so:
var usersByGender = users
.GroupBy(x => x.Gender)
.Select(group => new {Gender = group.Key, List = group.ToList()});
Which will result in a list of the generated anonymous type containing a Gender property and List<User> that are detectable by IntelliSense. The question is, can I somehow do this with properties in a generic class?
EDIT: I now realize I'm essentially asking for "method_missing" in C# 3.0, which is probably impossible. I'm open to suggestions, though.