I would like to be able to do something like this :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Test
{
This is a Type Covariance/Contravariance issue (see http://en.wikipedia.org/wiki/Covariance_and_contravariance_(computer_science)#C.23 ).
There's a workaround: use explicit interfaces, like so:
public class Bar : IFoo {
private IList _integers;
IEnumerable IFoo.integers {
get { return _integers };
set { _integers = value as IList; }
}
public IList integers {
get { return _integers; }
set { _integers = vale; }
}
}
Note that integers should be TitleCased to conform to .NET's guidelines.
Hopefully you can see the problem in the code above: IList is compatible with IEnumerable only for the accessor, but not for setting. What happens if someone calls IFoo.integers = new Qux (where Qux : IEnumerable but not Qux : IList).