Frage

I have a class ActiveList<T>: ObservableCollection<T> that I wish to store in a dictionary with key of Type, which is the T of ActiveList, something like:

Dictionary<Type, ActiveList<T>>

Of course the dictionary cannot be typed, as it should cater for different types for T. It may help if you know that T is constrained to XTimeEntity, so I could consider making the dictionary:

Dictionary<Type, ActiveList<XTimeEntity>>

but how would I cast an ActiveList<XtimeEntity> to an ActiveList<T> when I want Dictionary[T]?

War es hilfreich?

Lösung

Is there an Interface all ActiveLists share? Than you could have a Dictionary<Type, IActiveList>. But you would still have to cast the received value.

Andere Tipps

Why not use interface ?

Define an interface(IActive) to declare the method you want to realize, then implement it.

public class Acitve<T> : IActive

Add it to the Dictionary<Type, IActive>.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top