I have an Array of Interfaces to ObservableCollection-s of different, related types:
public IObsColD[] dsLists = new IObsColD[]
{
new ObsColD<DSection>(),
new ObsColD<DSection4>(),
new ObsColD<DSection5>()
};
public interface IObsColD { }
public class ObsColD<T> : ObservableCollection<T>, IObsColD where T : new()
{
public ObsColD() { }
public ObsColD(int n = 0)
{
for (int i = 0; i < n; i++)
this.Add(new T());
}
}
then somewhere in the program I assign dsLists[2] (an ObservableCollection of DSection5 type variables) to a parameter p, use p as an argument to function f and in f I try to do a foreach.
But then I need to know p's Type for re-casting. Or: I need to know if the ObsCol is a Collection of DSection5 or of DSection4 type variables.
How do I find out the type of p's Items at that moment?