/// <summary> /// This method returns the child nodes of a specified "path", where the path is just indices of nodes that /// point to the node whose children are returned. /// </summary> /// /// <remarks>This method is not used by this component and is implemented only to meet the /// interface requirements set forth by the ITreeViewLoader interface.</remarks> /// /// <exception cref="ArgumentNullException">If the given parameter is null</exception> /// <exception cref="ArgumentException"> /// ArgumentException if the parameter given is an empty array, if the array contains a negative value, or if no /// node matches the given path /// </exception> /// /// <param name="path">The path to the node whose children we return</param> /// /// <returns>The children of the node pointed to by the path</returns> public TreeNode[] LoadChildren(int[] path) { HelperClass.ValidateNotNull(path, "path"); // Check the array length. if (path.Length == 0) { throw new ArgumentException("Empty array is not allowed.", "path"); } //Get parent tree TreeNode parentNode = LoadTree(); // Check the array element. foreach (int pos in path) { if (pos < 0) { throw new ArgumentException("Negative path value is not allowed.", "path"); } if (pos >= parentNode.ChildCount) { throw new ArgumentException("Path value is not less than parentNode.ChildCount.", "path"); } parentNode = parentNode[pos]; } return((TreeNode[])((ArrayList)parentNode.Children).ToArray(typeof(TreeNode))); }
/// <summary> /// This method recursively creates TreeNodes based on the XmlNodes in the given parameter. This method /// looks at all Element type nodes, creating nodes for /// each attribute of the element, as well as for each node as a child of the Element that is only a text node. /// The leaf nodes are created with the following text format: "node.Name (node.Value)". /// Similar processing occurs for loading any children of the nodes. /// </summary> /// <exception cref="ArgumentNullException">ArgumentNullException if the given parameter is null</exception> /// <param name="children">The children Xml nodes to create TreeNodes from</param> /// <returns>All tree nodes created from the node list given</returns> protected virtual IList <TreeNode> LoadNodeChildren(XmlNodeList children) { HelperClass.ValidateNotNull(children, "children"); //Create the result list IList <TreeNode> result = new List <TreeNode>(); //Loop through all the given nodes foreach (XmlNode node in children) { //Only get Element nodes if (node.NodeType == XmlNodeType.Element) { //Handle child text nodes for showing in [Node Name] [(Node Text)] format string nodeInnerText = ExtractText(node); string nodeText = node.Name; if (nodeInnerText != null) { nodeText = String.Format(StandardNodeFormat, node.Name, nodeInnerText); } //Create the current TreeNode TreeNode thisTreeNode = new TreeNode(nodeText); //Create child TreeNode for each attribute foreach (XmlAttribute attr in node.Attributes) { TreeNode attrNode = new TreeNode(String.Format(StandardNodeFormat, attr.Name, attr.Value)); attrNode.IsExpanded = true; thisTreeNode.AddChild(attrNode); } //Recursively create hierarchy for the current node's child nodes //Add this whole hierarchy as the child of the current TreeNode IList <TreeNode> childTreeNodes = LoadNodeChildren(node.ChildNodes); foreach (TreeNode childTreeNode in childTreeNodes) { childTreeNode.IsExpanded = true; thisTreeNode.AddChild(childTreeNode); } //Add current TreeNode to the result collection thisTreeNode.IsExpanded = true; result.Add(thisTreeNode); } } return(result); }
public void ValidateNotNullFail() { object a = null; HelperClass.ValidateNotNull(a, "name"); }
public void ValidateNotNullAccuracy() { HelperClass.ValidateNotNull("abcd", "name"); HelperClass.ValidateNotNull(new object(), "name"); }