My Model
is a generic class that contains a (for example) Value
property which can be int, float, string, bool, etc. So naturally this class is represe
C# generics won't allow generic type as type parameter:
ObservableCollection>
Above is not only illegal in C#, but also makes no sense because it would break static type constraints.
I'm guessing what you really are trying to do is:
class ViewModel : IMyViewModel {...}
new ObservableCollection()
than you need some kind of factory that would produce IMyViewModel instances based on IModel runtime type:
public IMyViewModel CreateMyViewModel( IModel model){
if (model is Model)
return new ViewModel(model as Model);
if (model is Model)
return new ViewModel(model as Model);
...etc..
}
thus, having a
IEnumarable models = ...
you can get
var myVMs =
from m in models select CreateMyViewModel(m);
myCollection = new ObservableCollection(myVMs);