Fixing an issue with output parameters that are of type IntPtr
[castle.git] / Components / Binder / Castle.Components.Binder / Node.cs
blob42a08595e201a02b182df31abee2798a0187e168
1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle.Components.Binder
17 using System;
18 using System.Collections;
19 using System.Collections.Generic;
20 using System.Collections.Specialized;
22 public enum NodeType
24 Unspecified,
25 Composite,
26 Indexed,
27 Leaf
30 public abstract class Node
32 private readonly String name;
33 private readonly NodeType nodeType;
34 private Node parent;
36 protected Node(String name, NodeType nodeType)
38 this.name = name;
39 this.nodeType = nodeType;
42 public String Name
44 get { return name;}
47 public NodeType NodeType
49 get { return nodeType; }
52 public String FullName
54 get
56 if (Parent != null)
58 return string.Format("{0}.{1}", Parent.FullName, Name);
61 return Name;
65 public Node Parent
67 get { return parent; }
68 set { parent = value; }
72 public class CompositeNode : Node
74 private readonly HybridDictionary name2Node = new HybridDictionary(true);
75 private readonly List<Node> nodeList = new List<Node>();
77 public CompositeNode(String name) : base(name, NodeType.Composite)
81 protected CompositeNode(string name, NodeType nodeType) : base(name, nodeType)
85 public void AddChildNode(Node node)
87 if (node == null) throw new ArgumentNullException("node");
89 name2Node[node.Name] = node;
90 nodeList.Add(node);
91 node.Parent = this;
94 public Node GetChildNode(String name)
96 int index = name.IndexOf(".");
98 if (!name2Node.Contains(name) && index != -1)
100 string firstNodeName = name.Substring(0, index);
101 string remainingName = name.Substring(index + 1);
103 Node innerNode = (Node)name2Node[firstNodeName];
105 if (innerNode != null && innerNode.NodeType == NodeType.Composite)
107 return (innerNode as CompositeNode).GetChildNode(remainingName);
110 throw new BindingException("node is not Composite but still need to recurse to {0}", remainingName);
113 return (Node) name2Node[name];
116 public Node[] ChildNodes
118 get { return nodeList.ToArray(); }
121 public int ChildrenCount
123 get { return nodeList.Count; }
127 public class IndexedNode : CompositeNode
129 public IndexedNode(string name) : base(name, NodeType.Indexed)
134 public class LeafNode : Node
136 private readonly Type type;
137 private readonly object value;
139 public LeafNode(Type type, string name, object value) : base(name, NodeType.Leaf)
141 if (type == null) throw new ArgumentNullException("type", "A type must be specified");
142 if (value == null) throw new ArgumentNullException("value", "A value must be specified");
144 this.type = type;
145 this.value = value;
148 public Type ValueType
150 get { return type; }
153 public bool IsArray
155 get { return type.IsArray; }
158 public object Value
160 get { return value; }