Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class CheckList<T>
- {
- public delegate T Getter(List<T> list, int index);
- public delegate void Setter(List<T> list, int index, T value);
- private List<T> list;
- private Getter getter;
- private Setter setter;
- public CheckList(List<T> list, Getter getter, Setter setter)
- {
- this.list = list;
- this.getter = getter;
- this.setter = setter;
- }
- public T this[int index]
- {
- get
- {
- return getter(list, index);
- }
- set
- {
- setter(list, index, value);
- }
- }
- public int Count
- {
- get
- { return list.Count; }
- }
- public void Add(T value)
- {
- list.Add(value);
- }
- public void Remove(T value)
- {
- list.Remove(value);
- }
- }
- enum EntryType
- {
- Root,
- Local,
- House,
- Category,
- Product
- }
- class Entry
- {
- private string name;
- private string country;
- private EntryType type;
- private Entry parent;
- private List<Entry> children;
- public CheckList<Entry> Children;
- private Entry getChild(List<Entry> list, int index)
- {
- return list[index];
- }
- private void setChild(List<Entry> list, int index, Entry value)
- {
- if (value.Type == EntryType.Root) // Класс CheckList существует для этого условия
- {
- throw new ArgumentException();
- }
- list[index] = value;
- }
- public Entry()
- {
- children = new List<Entry>();
- Children = new CheckList<Entry>(children, getChild, setChild);
- }
- public string Name
- {
- get { return name; }
- set
- {
- if (value.Length == 0)
- throw new ArgumentException("некорректное название");
- name = value;
- }
- }
- public string Country
- {
- get { return country; }
- set
- {
- if (value.Length == 0)
- throw new ArgumentException("некорректное название страны");
- country = value;
- }
- }
- public EntryType Type
- {
- get { return type; }
- set { type = value; }
- }
- public Entry Parent
- {
- get
- { return parent; }
- set
- {
- if (type == EntryType.Root
- || type == EntryType.Local && value.Type != EntryType.Root
- || type == EntryType.House && value.Type != EntryType.Local
- || type == EntryType.Category && value.Type != EntryType.House && value.Type != EntryType.Category
- || type == EntryType.Product && value.Type != EntryType.Category)
- throw new ArgumentException("некорректный родитель");
- parent = value;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement