Question

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]?

Était-ce utile?

La solution

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.

Autres conseils

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>.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top