Hi, you can write your own "combined list" like in following console demo:
using System;
using System.Collections;
using System.Collections.Generic;
namespace ConsoleApp1
{
class Program25
{
static void Main(string[] args)
{
try
{
(new Demo()).Execute();
}
catch (Exception ex) { Console.WriteLine(ex.ToString()); }
Console.WriteLine("Continue enter key");
Console.ReadKey();
}
internal class Demo
{
internal void Execute()
{
List<MyItem> list1 = new List<MyItem>();
list1.Add(new MyItem() { Name = "Four", Value = 1 });
list1.Add(new MyItem() { Name = "Four", Value = 2 });
CombinedList<MyItem> list2 = new CombinedList<MyItem>(list1);
list2.Add(new MyItem() { Name = "Four", Value = 3 });
CombinedList<MyItem> list3 = new CombinedList<MyItem>(list1);
list3.Add(new MyItem() { Name = "Four", Value = 4 });
Console.WriteLine("--- combined list2");
foreach (var item in list2) Console.WriteLine($"{item.Name}, Value: {item.Value}");
Console.WriteLine("--- combined list3");
foreach (var item in list3) Console.WriteLine($"{item.Name}, Value: {item.Value}");
}
}
public class CombinedList<T> : IList<T>, ICollection<T>, IEnumerable<T>, IEnumerable, IList, ICollection, IReadOnlyList<T>, IReadOnlyCollection<T>
{
public CombinedList(List<T> primary)
{
externList = primary;
}
private List<T> externList;
private List<T> internList = new List<T>();
public T this[int index] { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public int Count => throw new NotImplementedException();
public bool IsReadOnly => throw new NotImplementedException();
public bool IsFixedSize => throw new NotImplementedException();
public object SyncRoot => throw new NotImplementedException();
public bool IsSynchronized => throw new NotImplementedException();
object IList.this[int index] { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public void Add(T item)
{
internList.Add(item);
}
public void Clear()
{
throw new NotImplementedException();
}
public bool Contains(T item)
{
throw new NotImplementedException();
}
public void CopyTo(T[] array, int arrayIndex)
{
throw new NotImplementedException();
}
public IEnumerator<T> GetEnumerator()
{
return new CombinedEnumerator<T>(externList, internList);
}
public int IndexOf(T item)
{
throw new NotImplementedException();
}
public void Insert(int index, T item)
{
throw new NotImplementedException();
}
public bool Remove(T item)
{
throw new NotImplementedException();
}
public void RemoveAt(int index)
{
throw new NotImplementedException();
}
IEnumerator IEnumerable.GetEnumerator()
{
throw new NotImplementedException();
}
public int Add(object value)
{
throw new NotImplementedException();
}
public bool Contains(object value)
{
throw new NotImplementedException();
}
public int IndexOf(object value)
{
throw new NotImplementedException();
}
public void Insert(int index, object value)
{
throw new NotImplementedException();
}
public void Remove(object value)
{
throw new NotImplementedException();
}
public void CopyTo(Array array, int index)
{
throw new NotImplementedException();
}
public class CombinedEnumerator<U> : IEnumerator<U>
{
public CombinedEnumerator(List<U> externList, List<U> internList)
{
this.externList = externList;
this.internList = internList;
}
private List<U> externList;
private List<U> internList;
private int i = -1;
public U Current => (i < externList.Count) ? externList[i] : internList[i - externList.Count];
object IEnumerator.Current => throw new NotImplementedException();
public void Dispose() { }
public bool MoveNext()
{
i++;
return i < internList.Count + externList.Count;
}
public void Reset() => i = -1;
}
}
public class MyItem
{
public string Name;
public int Value;
}
}
}