0
|
1 using System;
|
|
2 using System.Collections.Generic;
|
|
3
|
|
4 namespace BLToolkit.Data.Sql
|
|
5 {
|
|
6 public class ChildContainer<TP,TC> : Dictionary<string,TC>, IDictionary<string,TC>
|
|
7 where TC : IChild<TP>
|
|
8 where TP : class
|
|
9 {
|
|
10 internal ChildContainer()
|
|
11 {
|
|
12 }
|
|
13
|
|
14 internal ChildContainer(TP parent)
|
|
15 {
|
|
16 _parent = parent;
|
|
17 }
|
|
18
|
|
19 readonly TP _parent;
|
|
20 public TP Parent { get { return _parent; } }
|
|
21
|
|
22 public void Add(TC item)
|
|
23 {
|
|
24 Add(item.Name, item);
|
|
25 }
|
|
26
|
|
27 public new void Add(string key, TC value)
|
|
28 {
|
|
29 if (value.Parent != null) throw new InvalidOperationException("Invalid parent.");
|
|
30 value.Parent = _parent;
|
|
31
|
|
32 base.Add(key, value);
|
|
33 }
|
|
34
|
|
35 public void AddRange(IEnumerable<TC> collection)
|
|
36 {
|
|
37 foreach (var item in collection)
|
|
38 Add(item);
|
|
39 }
|
|
40 }
|
|
41 }
|