Please see an example of my code below:
CODE UPDATED
public class ScrollableCheckboxList
{
public List<ScrollableCheckboxItem> listitems;
public ScrollableCheckboxList<TModel>(IEnumerable<TModel> items, string valueField, string textField, string titleField) where TModel : class
{
listitems = new List<ScrollableCheckboxItem>();
foreach (TModel item in items)
{
Type t = typeof(TModel);
PropertyInfo[] props = new [] { t.GetProperty(textField), t.GetProperty(valueField), t.GetProperty(titleField) };
listitems.Add(new ScrollableCheckboxItem
{
text = props[0].GetValue(item, null).ToString(),
value = props[1].GetValue(item, null).ToString(),
title = props[2].GetValue(item, null).ToString()
});
}
}
}
EDIT Corrections to constructor declaration made! Still a problem with this code though
The code wont compile - it comes up with lots of strange little errors making me think that there's a design problem here?