예제 #1
0
    public SingletonTree()
    {
        if (_isFirst)
        {
            _dicNode.Add(ROOT_KEY, _root);
            InitNode();
            _isFirst = false;
        }

        string currentKey = typeof(TOwnerClass).ToString();

        _currentNode = _root.FindChild(currentKey);
    }
예제 #2
0
 /// クラス名で指定したインスタンスを取得(親にさかのぼりながら探索する)
 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));
     }
 }
예제 #3
0
    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);
    }
예제 #4
0
 protected bool Equals(SingletonNode other)
 {
     return(string.Equals(Caption, other.Caption));
 }
예제 #5
0
 public void AddChild(string key, SingletonNode child)
 {
     child.SetParent(this);
     _children.Add(key, child);
 }
예제 #6
0
 public void SetParent(SingletonNode parent)
 {
     _parent = parent;
 }
예제 #7
0
 public static void Clear()
 {
     _root    = null;
     _dicNode = null;
 }
예제 #8
0
 protected void AddNode(SingletonNode parent, TNodeKey childKey, SingletonNode childNode)
 {
     _dicNode.Add(childKey.ToString(), childNode);
     parent.AddChild(childKey.ToString(), childNode);
 }