convert List<List<object>> to IList<IList<object>>
Does Enumerable.Cast<T> Copy Objects?
https://msdn.microsoft.com/en-us/library/ms668604(v=vs.110).aspx
https://msdn.microsoft.com/en-us/library/ms132397(v=vs.110).aspx
My class, Person, implements my interface, ISequenced.
I have an ObservableCollection<Person> which I need to pass to a method which takes as a parameter an object of type IList<ISequenced> My question is how do I pass the ObservableCollection - without making a copy - such that the called function can modify it.
Note that the answer to this question: Is there a way to convert an observable collection to regular collection? demonstrates .ToList() which creates a new object.
public interface ISequenced
{
int Sequence { get; set; }
}
public class Person : ISequenced
{
public int Sequence {get; set;}
//...
}
public class MyCode
{
public ObservableCollection<Person> Entities {get; set;}
public Person CurrentItem {get;set;}
private void MoveDown()
{
IEnumerable<ISequenced> seq = Entities.Cast<ISequenced>(); // works but we need IList not IEnumerable
IList<Person> p = (IList<Person>)Entities; // works but we need IList ISequenced
IList<ISequenced> pp = (IList<ISequenced>)p; // throws
// Need to pass a reference to Entities.... throws unable to cast here
Sequencer.SequenceDown((IList<ISequenced>)Entities, CurrentItem as ISequenced);
}
}
public static class Sequencer
{
public static void SequenceDown(IList<ISequenced> items, ISequenced currentItem)
{
// swap the positions of two elements in the collection here
}
}