In my interfaces there is typically an IList<ISomeType>
to represent List-type members
and to say that I expect an implementation supporting an Add
method.
But in the interface implementation, there is an
IList<ISomeType> = new List<ISomeType>()
and everytime I use the List, I have to cast, for example
(this.MyList as List<IMyType>).AddRange(someType.ToList());
Is there a better way to do this? How to avoid this cast?
- edit to ask for more information -
Instead of a extension method, is there a small linq expression to solve that?
IList<string> list = new List<string>();
var items = new[] { "1", "2", "3" };
items.ToList().ForEach(x => list.Add(x));
But this does not look like being very straight forward, as it inverts what is being done. (the action is on the items to add, not on the list).
Anything better than that? Possible something that can be done on the list?