public SingletonTree() { if (_isFirst) { _dicNode.Add(ROOT_KEY, _root); InitNode(); _isFirst = false; } string currentKey = typeof(TOwnerClass).ToString(); _currentNode = _root.FindChild(currentKey); }
/// クラス名で指定したインスタンスを取得(親にさかのぼりながら探索する) private T GetWithClassName <T>(string className, SingletonNode node) { if (_dicInstance.ContainsKey(className)) { /// 自分がそのクラスのインスタンスを保持していれば返す return((T)_dicInstance[className]); } else { /// ないので親に聞いてみる if (_parent == null) { /// 親なしなので見つからない throw new Exception(string.Format("指定されたクラス{0}は{1}Nodeに登録されていません。;", className, node)); } return(_parent.GetWithClassName <T>(className, node)); } }
protected override void InitNode() { TempDataA tempDataA = new TempDataA(); TempDataA1 tempDataA1 = new TempDataA1(); TempDataB tempDataB = new TempDataB(); SingletonNode a = new SingletonNode(); a.AddInstance(tempDataA); a.AddInstance(tempDataA1); SingletonNode b = new SingletonNode(); b.AddInstance(tempDataB); SingletonNode aa = new SingletonNode(); AddNode(_root, typeof(TestTreeA), a); AddNode(_root, typeof(TestTreeB), b); AddNode(a, typeof(TestTreeAA), aa); }
protected bool Equals(SingletonNode other) { return(string.Equals(Caption, other.Caption)); }
public void AddChild(string key, SingletonNode child) { child.SetParent(this); _children.Add(key, child); }
public void SetParent(SingletonNode parent) { _parent = parent; }
public static void Clear() { _root = null; _dicNode = null; }
protected void AddNode(SingletonNode parent, TNodeKey childKey, SingletonNode childNode) { _dicNode.Add(childKey.ToString(), childNode); parent.AddChild(childKey.ToString(), childNode); }