/// <summary> /// Gets a ReflectionTreeNode from a type's namespace /// </summary> /// <param name="parent"></param> /// <param name="fullPath"></param> /// <returns></returns> private ReflectionTreeNode GetNode(ReflectionTreeNode parent, string fullPath) { if (fullPath == null) { return(null); } // split up the namespace string[] namespaces = fullPath.Split(new char[] { '.' }); ReflectionTreeNode node = null; if (namespaces.Length > 0) { string elementName = namespaces[0]; if (parent == null) { if (_nodes.Contains(elementName)) { node = (ReflectionTreeNode)_nodes[elementName]; } } else { } if (node == null) { node = new ReflectionTreeNode(elementName); node.ImageIndex = 11; node.SelectedImageIndex = 11; if (parent == null) { _treeViewGACTypes.Nodes.Add(node); } else { parent.Nodes.Add(node); } _nodes.Add(elementName, node); // cache the node } string remainingPath = string.Join(".", namespaces, 1, namespaces.Length - 1); if (remainingPath != null) { if (remainingPath != string.Empty) { node = GetNode(node, remainingPath); } } } return(node); }
/// <summary> /// Loads all of the types found from the specified reference /// </summary> /// <param name="reference">The reference to load types from</param> public void LoadTypesFromReference(string reference) { try { Assembly assembly = this.LoadReference(reference); if (assembly != null) { // get the exported types from the assembly Type[] types = assembly.GetExportedTypes(); if (types != null) { foreach (Type t in types) { if (t.IsPublic && (!t.IsAbstract)) { // object[] attributes = t.GetCustomAttributes(typeof(SerializableAttribute), false); // bool isSerializable = false; // if ((attributes != null) && (attributes.Length > 0)) // { // foreach(object attribute in attributes) // if (attribute is SerializableAttribute) // { // isSerializable = true; // break; // } // } // bool supportsISerializable = (t.GetInterface(typeof(System.Runtime.Serialization.ISerializable).FullName) != null); // if (isSerializable || supportsISerializable) // { ReflectionTreeNode namespaceParent = this.GetNodeByPath(null, t.Namespace); ReflectionTreeNode node = new ReflectionTreeNode(t.Name); node.Assembly = assembly; node.Type = t; int imageIndex = this.GetTypeImageIndex(t); node.ImageIndex = imageIndex; node.SelectedImageIndex = imageIndex; if (namespaceParent != null) { namespaceParent.Nodes.Add(node); } // } } } } } } catch (System.Exception systemException) { System.Diagnostics.Trace.WriteLine(systemException); } }
private ReflectionTreeNode GetNodeByPath(ReflectionTreeNode parent, string fullPath) { // bail if there is no path to look up if (fullPath == null) { return(null); } // look in the cache first, before trying to do a ton of work to create the node if (_nodes.Contains(fullPath)) { return((ReflectionTreeNode)_nodes[fullPath]); } // snag hold of a node collection from the parent TreeNodeCollection nodes = (parent != null ? parent.Nodes : _treeViewGACTypes.Nodes); // split the node path down into it's individual paths String[] paths = fullPath.Split(new char[] { '.' }); // make a node that will be the target or null when the full path is resolved ReflectionTreeNode targetNode = null; // start making the paths // foreach(string path in paths) // { foreach (ReflectionTreeNode node in nodes) { if (node.Text == paths[0]) { targetNode = node; break; } } if (targetNode == null) { // create it targetNode = new ReflectionTreeNode(paths[0]); targetNode.ImageIndex = 11; targetNode.SelectedImageIndex = 11; // add the node to the tree nodes.Add(targetNode); // cache it by it's full path _nodes.Add(targetNode.FullPath, targetNode); } // we found a path, recurse into it string subPath = string.Join(".", paths, 1, paths.Length - 1); if (subPath != null) { if (subPath != string.Empty) { targetNode = GetNodeByPath(targetNode, subPath); } } // } return(targetNode); }
/// <summary> /// Gets a ReflectionTreeNode from a type's namespace /// </summary> /// <param name="parent"></param> /// <param name="fullPath"></param> /// <returns></returns> private ReflectionTreeNode GetNode(ReflectionTreeNode parent, string fullPath) { if (fullPath == null) return null; // split up the namespace string[] namespaces = fullPath.Split(new char[] {'.'}); ReflectionTreeNode node = null; if (namespaces.Length > 0) { string elementName = namespaces[0]; if (parent == null) { if (_nodes.Contains(elementName)) node = (ReflectionTreeNode)_nodes[elementName]; } else { } if (node == null) { node = new ReflectionTreeNode(elementName); node.ImageIndex = 11; node.SelectedImageIndex = 11; if (parent == null) _treeViewGACTypes.Nodes.Add(node); else parent.Nodes.Add(node); _nodes.Add(elementName, node); // cache the node } string remainingPath = string.Join(".", namespaces, 1, namespaces.Length - 1); if (remainingPath != null) if (remainingPath != string.Empty) node = GetNode(node, remainingPath); } return node; }
private ReflectionTreeNode GetNodeByPath(ReflectionTreeNode parent, string fullPath) { // bail if there is no path to look up if (fullPath == null) return null; // look in the cache first, before trying to do a ton of work to create the node if (_nodes.Contains(fullPath)) return (ReflectionTreeNode)_nodes[fullPath]; // snag hold of a node collection from the parent TreeNodeCollection nodes = (parent != null ? parent.Nodes : _treeViewGACTypes.Nodes); // split the node path down into it's individual paths String[] paths = fullPath.Split(new char[] {'.'}); // make a node that will be the target or null when the full path is resolved ReflectionTreeNode targetNode = null; // start making the paths // foreach(string path in paths) // { foreach(ReflectionTreeNode node in nodes) { if (node.Text == paths[0]) { targetNode = node; break; } } if (targetNode == null) { // create it targetNode = new ReflectionTreeNode(paths[0]); targetNode.ImageIndex = 11; targetNode.SelectedImageIndex = 11; // add the node to the tree nodes.Add(targetNode); // cache it by it's full path _nodes.Add(targetNode.FullPath, targetNode); } // we found a path, recurse into it string subPath = string.Join(".", paths, 1, paths.Length - 1); if (subPath != null) if (subPath != string.Empty) targetNode = GetNodeByPath(targetNode, subPath); // } return targetNode; }
/// <summary> /// Loads all of the types found from the specified reference /// </summary> /// <param name="reference">The reference to load types from</param> public void LoadTypesFromReference(string reference) { try { Assembly assembly = this.LoadReference(reference); if (assembly != null) { // get the exported types from the assembly Type[] types = assembly.GetExportedTypes(); if (types != null) { foreach(Type t in types) { if (t.IsPublic && (!t.IsAbstract)) { // object[] attributes = t.GetCustomAttributes(typeof(SerializableAttribute), false); // bool isSerializable = false; // if ((attributes != null) && (attributes.Length > 0)) // { // foreach(object attribute in attributes) // if (attribute is SerializableAttribute) // { // isSerializable = true; // break; // } // } // bool supportsISerializable = (t.GetInterface(typeof(System.Runtime.Serialization.ISerializable).FullName) != null); // if (isSerializable || supportsISerializable) // { ReflectionTreeNode namespaceParent = this.GetNodeByPath(null, t.Namespace); ReflectionTreeNode node = new ReflectionTreeNode(t.Name); node.Assembly = assembly; node.Type = t; int imageIndex = this.GetTypeImageIndex(t); node.ImageIndex = imageIndex; node.SelectedImageIndex = imageIndex; if (namespaceParent != null) namespaceParent.Nodes.Add(node); // } } } } } } catch(System.Exception systemException) { System.Diagnostics.Trace.WriteLine(systemException); } }