Sometimes you want to implement an interface that looks like this:
public interface ITraversable<T> {
List<T> Children { get; }
}
But sometimes you need a different collection class like this:
public interface ITraversable<T> {
ObservableCollection<T> Children { get; }
}
But you don't want to repeat yourself, so you try this interface:
public interface ITraversable<T> {
IEnumerable<T> Children { get; }
}
But any implementing class that uses List or ObservableCollection will get an error:
Error CS0738 'Tester' does not implement interface member 'ITraversable.Children'. 'Tester.Children' cannot implement 'ITraversable.Children' because it does not have the matching return type of 'IEnumerable'.
Is it possible to create a single interface with a generic interface property that can be used by multiple concrete class implementations?