I find that I need to write the same code in many classes. The code has to do with conversion between types. As I am not familiar with generics, would someone suggest how to convert the following to use generics:
public class WidgetList : List<Widget> { }
public class Widget
{
public int Id { get; set; }
public string Name { get; set; }
public Widget() { }
public Widget(int Id, string Name)
{
this.Id = Id;
this.Name = Name;
}
}
public class WidgetManager
{
public static List<Widget> ToListType(WidgetList list)
{
return list.ToList<Widget>();
}
public static WidgetList ToTypeList(List<Widget> list)
{
WidgetList typeList = new WidgetList();
foreach (Widget item in list)
{
typeList.Add(w);
}
return typeList;
}
}