mardi 1 mai 2018

Register to ObservableCollection

I've one "base" class, in which I want to observe any change made.

For all the properties, I go through a GetValue<T>() and SetValue<T>(). Then I've a Dictionary of backing field, stored with the CallerMemberName as key.

When doing a SetValue<T>(), I would like that if T is an ObservableCollection<AnyThing> to register to the CollectionChanged event(or unregister the previous value).

Any idea how I could achieve this?

public void RegisterIfObservable<T>(T value){
    Type type = typeof(T);
    if(type.IsGenericType && type.GetGenericTypeDefinition() == typeof(ObservableCollection<>)){
        //TODO Register
    }   
}

The goal would be to create an object at each insert/remove

new UndoableListAddAction<T>(ObservableCollection<T> collection, T addedElement)





Aucun commentaire:

Enregistrer un commentaire