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.
How do I store a collection of ObservableCollection<T> with different types for T?
-
05-08-2022 - |
Domanda
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]
?
Soluzione
Altri suggerimenti
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>
.
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow