Trzeba stworzyć generyczną metodkę.
Lecz listy i słowniki mają troszkę inną strukture. Obawiam się ze jedna metodka nie wystarczy
class Event { }
class Person { }
class GenericTest
{
public List<Person> Persons { get; set; }
public Dictionary<int, Event> EventsDic { get; set; }
public ObservableCollection<Event> Events { get; set; }
public GenericTest()
{
Persons = new List<Person>();
Events = new ObservableCollection<Event>();
EventsDic = new Dictionary<int, Event>();
AddObject<Event>(Events, new Event());
AddObject<Person>(Persons, new Person());
AddObject<int,Event>(EventsDic, new KeyValuePair<int, Event>());
}
private void AddObject<T>(ICollection<T> list, T obj)
{
list.Add(obj);
}
private void AddObject<TKey, TValue>(ICollection<KeyValuePair<TKey, TValue>> list, KeyValuePair<TKey, TValue> obj)
{
list.Add(obj);
}
}