[Обозвать] Коллекция, элементы ссылаются на контейнер
От: Sinix  
Дата: 05.05.10 08:00
Оценка:
А как бы вы обозвали collection base-класс, автоматически связывающий добавляемые элементы с каким-то контейнером?
Временное был обозван MappedCollectionBase. Binded использовать не хочется — binding в фреймворке имеет слегка другой смысл. Есть варианты получше?

Очень упрощённо (без проверок и отвязки):
  Скрытый текст

  public abstract class XxxCollectionBase<TContainer, TItem>: Collection<TItem>
  {
    public TContainer Container
    {
      get;
      set;
    }

    protected abstract void SetContainer(TItem item, TContainer container);

    protected override void InsertItem(int index, TItem item)
    {
      base.InsertItem(index, item);
      SetContainer(item, this.Container);
    }
  }

  public class Container
  {
    public class ItemsCollection: XxxCollectionBase<Container, Item>
    {
      protected override void SetContainer(Item item, Container container)
      {
        item.Container = container;
      }
    }

    private readonly ItemsCollection items;

    public Container()
    {
      items = new ItemsCollection()
      {
        Container = this
      };
    }

    public ItemsCollection Items
    {
      get
      {
        return items;
      }
    }
  }

  public class Item
  {
    public Container Container
    {
      get;
      set;
    }
  }
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.