1

コレクションにいくつかのデータを入れたいと思います。私はすでに解決策を持っていますが、それをより一般的で見苦しくないようにしたいと考えています。私見のネストされた辞書はあまり役に立ちません。

private static Dictionary<enumRoot, Dictionary<enumLevel1, Dictionary<enumLevel2, Tuple<int, bool, string>>>>

したがって、各ノード/レベルには、列挙型で表されるキーが必要です。最後 (タプル ATM) には何らかのオブジェクトが必要です。複合パターンのようなある種の再帰的アプローチを実装することを考えました。リストまたはリストを使用してオブジェクトを構築し、それぞれを追加することを考えました。

TreeNodeCollection をググったのですが、あまり情報が見つかりませんでした。このコレクションは私のケースで機能しますか? また、この問題をどのように予測できますか?

4

1 に答える 1

0

カスタム に依存することで、ノードベースの構造を構築できますClass。例:

public enum nodeName { nodeName1, nodeName2, nodeName3 };
public enum nodeAttribute { nodeAttribute1, nodeAttribute2, nodeAttribute3 };
public class Node
{
    public nodeName name { get; set; }
    public Node parent { get; set; }
    public Dictionary<nodeAttribute, string> attributes { get; set; }
    public List<Node> children { get; set; }
}

これには、次のようなものを簡単に入力できます。

Node node1 = new Node();
Node node2 = new Node();

node1.name = nodeName.nodeName1;
node1.parent = null;
node1.attributes = new Dictionary<nodeAttribute, string>();
node1.attributes.Add(nodeAttribute.nodeAttribute1, "1");
node1.attributes.Add(nodeAttribute.nodeAttribute2, "2");
node1.children = new List<Node>();
node1.children.Add(node2);
于 2013-07-24T11:55:12.960 に答える