public static System.Text.StringBuilder GetClassHierarchyForAssembly(System.Reflection.Assembly assembly) { var classTypes = assembly.GetExportedTypes().Where(type => type.IsClass); var classTreeNodes = new Dictionary <string, ClassTreeNode>(); foreach (Type classType in classTypes) { var newTreeNode = new ClassTreeNode(classType.Name); var parentIdentifier = classType.BaseType.Name; if (!classTreeNodes.TryGetValue(parentIdentifier, out ClassTreeNode parentNode)) { parentNode = new ClassTreeNode(parentIdentifier); classTreeNodes.Add(parentIdentifier, parentNode); } classTreeNodes.Add(newTreeNode.TypeName, newTreeNode); parentNode.AddChild(newTreeNode); } var builder = new System.Text.StringBuilder(); foreach (var node in classTreeNodes.Values.Where(it => it.Parent == null).OrderBy(it => it.TypeName)) { Display(builder, "", node); } return(builder); }
public void AddChild(ClassTreeNode child) { if (child.Parent != null) { throw new InvalidOperationException("Class already has a parent."); } this._children.Add(child); child.Parent = this; }
private void LoadStruct(TreeNode parentNode, Type td) { TreeNode node; if (td.IsPublic) { node = new ClassTreeNode(td, ClassType.Struct, Access.Public); parentNode.Nodes.Add(node); } else if (td.IsNestedPrivate) { node = new ClassTreeNode(td, ClassType.Struct, Access.Private); parentNode.Nodes.Add(node); } else if (td.IsNestedFamORAssem) { node = new ClassTreeNode(td, ClassType.Struct, Access.Internal); parentNode.Nodes.Add(node); } else { // It must be protected. node = new ClassTreeNode(td, ClassType.Struct, Access.Protected); parentNode.Nodes.Add(node); } foreach (Type ntd in td.GetNestedTypes()) { LoadType(node, ntd); } foreach (MethodInfo md in td.GetMethods()) { LoadMethod(node, md); } foreach (Type ntd in td.GetInterfaces()) { LoadImplementedInterface(node, ntd); } foreach (EventInfo ed in td.GetEvents()) { LoadEvent(node, ed); } foreach (PropertyInfo pd in td.GetProperties()) { LoadProperty(node, pd); } foreach (FieldInfo fd in td.GetFields()) { LoadField(node, fd); } }
//private void LoadConstant(TreeNode parentNode, PropertyInfo ptd) //{ // //TreeNode tr = new FieldTreeNode(fd, Access.Protected, false); // //parentNode.Nodes.Add(tr); // parentNode.Nodes.Add(ptd.FullName, ptd.Name, Constants.ConstantIcon, Constants.ConstantIcon); //} #region LoadEnum private void LoadEnum(TreeNode parentNode, Type td) { TreeNode enode; TreeNode tr; if (td.IsPublic) { enode = new ClassTreeNode(td, ClassType.Enum, Access.Public); parentNode.Nodes.Add(enode); } else if (td.IsNestedPrivate) { enode = new ClassTreeNode(td, ClassType.Enum, Access.Private); parentNode.Nodes.Add(enode); } else if (td.IsNestedFamORAssem) { enode = new ClassTreeNode(td, ClassType.Enum, Access.Internal); parentNode.Nodes.Add(enode); } else { // It must be protected. enode = new ClassTreeNode(td, ClassType.Enum, Access.Protected); parentNode.Nodes.Add(enode); } // Now we get to load it's values. foreach (FieldInfo fd in td.GetFields()) { // We don't want to show "value__" because it's automatically added // by the compiler. if (fd.Name != "value__") { tr = new FieldTreeNode(fd, Access.Public, true); enode.Nodes.Add(tr); } } }
private static void Display(System.Text.StringBuilder builder, string indentation, ClassTreeNode node) { Write(builder, indentation, node.TypeName); var childIdentation = String.Concat(" ", indentation); foreach (var child in node.Children.OrderBy(it => it.TypeName)) { Display(builder, childIdentation, child); } }
private SubClassTreeNode CreateRootNode() { var data = GenDataEditorViewModel.Data; return(ClassTreeNode.CreateRootNode(data)); }
public void OnType(ClassTreeNode node) { Level = 0; }
private void createClassList(CodeElement element, OutlineItem parent) { try { // if it's a namespace, expand each of its members if (element.Kind == vsCMElement.vsCMElementNamespace) { var codeNamespace = element as CodeNamespace; if (codeNamespace != null) { var members = codeNamespace.Members; for (var i = 1; i <= members.Count; i++) { createClassList(members.Item(i), parent); } } } // if it's a class... else if (element.Kind == vsCMElement.vsCMElementClass) { var cls = (CodeClass)element; var tn = new ClassTreeNode(cls); var child = new OutlineItem(); parent.AddChild(child); child.Name = cls.Name; child.ToolTipText = createClassSummary(cls.DocComment); child.FullName = element.FullName; child.BaseTypeName = tn.GetBaseTypeName(); child.ImageUri = new Uri("/Resources/Classes.png", UriKind.Relative); child.GotoCodeLocationEventHandler += gotoCodeLocation; child.OpenProjectItemEventHandler += openProjectItem; child.ProjectItem = cls.ProjectItem; child.UpdateViewsEventHandler += UpdateViewItems; if (FireflyImagesEnabled && tn.BaseClassList.Any(x => x.Contains("UIController"))) { child.ImageUri = new Uri("/Resources/UIController.png", UriKind.Relative); } child.StartLineOfCode = element.StartPoint.Line; child.StartLineOfCodeOffset = element.StartPoint.LineCharOffset; child.EndLineOfCode = element.EndPoint.Line; var members = ((CodeClass)element).Members; // expand each of the class's members for (var i = 1; i <= members.Count; i++) { createClassList(members.Item(i), child); } } // else, we are at a regular code element (field, property, method, etc.) else { // add methods if (element.Kind == vsCMElement.vsCMElementFunction) { var f = (CodeFunction2)element; var priority = getMethodPriority(f); if (priority > 0) { var signature = getSignature(f); parent.AddMethod(new OutlineItem.Method() { SortOrder = -priority, Signature = signature, LineNumber = f.StartPoint.Line, Name = getFunctionName(f), FullName = f.FullName, Category = "Override", Comment = f.DocComment ?? f.Comment }); } } //expandNonClassElements(element, parent, items, hierarchyItem); } } catch (Exception e) { _log.Error("Failed createClassList", e); } }
void onReportOpened(object sender, EventArgs e) { BeginUpdate(); ICoverageReport report = serviceContainer.GetService<ICoverageReportService>().Report; foreach (IAssembly assembly in report.GetAssemblies()) { AssemblyTreeNode asmNode = new AssemblyTreeNode(assembly); Nodes.Add(asmNode); foreach (IClass dType in assembly.GetTypes()) { TreeNode namespaceNode = GetNamespaceNode(asmNode, dType); ClassTreeNode classNode = new ClassTreeNode(dType); namespaceNode.Nodes.Add(classNode); Dictionary<string, PropertyTreeNode> props = new Dictionary<string, PropertyTreeNode>(); foreach (IMethod md in dType.GetMethods()) { if (!Methods.isSpecial(md.Flags)) { AddMethodTreeNode(classNode, md); continue; } //has special meaning MdSpecial mdSpecial = Methods.getMdSpecial(md.Name); if (mdSpecial == MdSpecial.Unknown) { AddMethodTreeNode(classNode, md); continue; } string propName = Methods.getMdSpecialName(md.Name); PropertyTreeNode propertyNode; if (!props.TryGetValue(propName, out propertyNode)) { propertyNode = new PropertyTreeNode(propName); props[propName] = propertyNode; classNode.Nodes.Add(propertyNode); } MethodTreeNode mdNode = new MethodTreeNode(md); mdNode.MethodName = mdSpecial.ToString().ToLowerInvariant(); switch (mdSpecial) { case MdSpecial.Get: mdNode.ImageIndex = ImageSelector.forPropertyGet(md); mdNode.SelectedImageIndex = ImageSelector.forPropertyGet(md); propertyNode.Getter = mdNode; break; case MdSpecial.Remove: mdNode.ImageIndex = ImageSelector.forEventRemove(md); mdNode.SelectedImageIndex = ImageSelector.forEventRemove(md); propertyNode.Getter = mdNode; break; case MdSpecial.Set: mdNode.ImageIndex = ImageSelector.forPropertySet(md); mdNode.SelectedImageIndex = ImageSelector.forPropertySet(md); propertyNode.Setter = mdNode; break; case MdSpecial.Add: mdNode.ImageIndex = ImageSelector.forEventAdd(md); mdNode.SelectedImageIndex = ImageSelector.forEventAdd(md); propertyNode.Setter = mdNode; break; } } foreach (KeyValuePair<string, PropertyTreeNode> kv in props) { if (kv.Value.Getter != null) kv.Value.Nodes.Add(kv.Value.Getter); if (kv.Value.Setter != null) kv.Value.Nodes.Add(kv.Value.Setter); } } asmNode.UpdateCoverageInfo(); } EndUpdate(); }
private void CreateNodes(TreeNodeCollection treeNodeCollection, string[] parts, int index, ref string parent) { if (!treeNodeCollection.ContainsKey(parts[index])) { string extension = Path.GetExtension(parts[index]); ResourceTreeNode node; switch (extension) { case "": node = new FolderTreeNode(); node.Text = Path.ChangeExtension(parts[index], null); node.Name = parts[index]; string path = string.Empty; for (int i = 0; i <= index; i++) path = Path.Combine(path, parts[i]); node.Path = Path.Combine(parent, path); treeNodeCollection.Add(node); break; case Sunfish.Tag.Path.Extension: node = new ClassTreeNode(); node.Text = Path.ChangeExtension(parts[index], null); node.Name = parts[index]; path = string.Empty; foreach (string s in parts) path = Path.Combine(path, s); node.Path = Path.Combine(parent, path); treeNodeCollection.Add(node); break; } } if (parts.Length > index + 1) CreateNodes(treeNodeCollection[treeNodeCollection.IndexOfKey(parts[index])].Nodes, parts, index + 1, ref parent); }
private void LoadTag(ClassTreeNode node) { foreach (DockContent dc in this.PrimaryDock.Documents) if ((string)(dc.Tag) == node.Path) { dc.Activate(); return; } switch (Sunfish.Tag.Path.GetTagType(node.Path)) { case "scnr": MetaTool mt = new MetaTool(); mt.Text = Explorer.treeView1.SelectedNode.Text; mt.Show(this.PrimaryDock, WeifenLuo.WinFormsUI.Docking.DockState.Document); Sunfish.Tag scnr = new Tag(node.Path); mt.LoadTag(scnr); break; case "bitm": BitmapTool bt = new BitmapTool(); bt.Text = Explorer.treeView1.SelectedNode.Text; bt.Show(this.PrimaryDock, WeifenLuo.WinFormsUI.Docking.DockState.Document); break; case "mode": ModelEditor modeEdit = new ModelEditor(); modeEdit.Text = Explorer.treeView1.SelectedNode.Text; modeEdit.Show(this.PrimaryDock, WeifenLuo.WinFormsUI.Docking.DockState.Document); modeEdit.LoadTag(node.Path); break; case "coll": ModelEditor collEdit = new ModelEditor(); collEdit.Text = Explorer.treeView1.SelectedNode.Text; collEdit.Show(this.PrimaryDock, WeifenLuo.WinFormsUI.Docking.DockState.Document); collEdit.LoadTag(node.Path); break; default: mt = new MetaTool(); mt.Text = Explorer.treeView1.SelectedNode.Text; mt.Show(this.PrimaryDock, WeifenLuo.WinFormsUI.Docking.DockState.Document); Sunfish.Tag tag = new Tag(node.Path); mt.LoadTag(tag); break; } }
void OnReportOpened(object sender, EventArgs e) { BeginUpdate(); var report = serviceContainer.getService<IReportService>().Report; foreach (var assembly in report.Assemblies) { var asmNode = new AssemblyTreeNode(assembly); Nodes.Add(asmNode); foreach (var dType in assembly.Types) { var namespaceNode = GetNamespaceNode(asmNode, dType); var classNode = new ClassTreeNode(dType); namespaceNode.Nodes.Add(classNode); var props = new Dictionary<string, PropertyTreeNode>(); foreach (var md in dType.Methods) { if (!Methods.IsSpecial(md.Flags)) { AddMethodTreeNode(classNode, md); continue; } //has special meaning var mdSpecial = Methods.GetMdSpecial(md.Name); if (mdSpecial == MdSpecial.Unknown) { AddMethodTreeNode(classNode, md); continue; } var propName = Methods.GetMdSpecialName(md.Name); PropertyTreeNode propertyNode; if (!props.TryGetValue(propName, out propertyNode)) { propertyNode = new PropertyTreeNode(propName); props[propName] = propertyNode; classNode.Nodes.Add(propertyNode); } var mdNode = new MethodTreeNode(md) { //MethodName = mdSpecial.ToString().ToLowerInvariant() }; switch (mdSpecial) { case MdSpecial.Get: mdNode.ImageIndex = ImageSelector.ForPropertyGet(md); mdNode.SelectedImageIndex = ImageSelector.ForPropertyGet(md); propertyNode.Getter = mdNode; break; case MdSpecial.Remove: mdNode.ImageIndex = ImageSelector.ForEventRemove(md); mdNode.SelectedImageIndex = ImageSelector.ForEventRemove(md); propertyNode.Getter = mdNode; break; case MdSpecial.Set: mdNode.ImageIndex = ImageSelector.ForPropertySet(md); mdNode.SelectedImageIndex = ImageSelector.ForPropertySet(md); propertyNode.Setter = mdNode; break; case MdSpecial.Add: mdNode.ImageIndex = ImageSelector.ForEventAdd(md); mdNode.SelectedImageIndex = ImageSelector.ForEventAdd(md); propertyNode.Setter = mdNode; break; } } foreach (var kv in props) { if (kv.Value.Getter != null) kv.Value.Nodes.Add(kv.Value.Getter); if (kv.Value.Setter != null) kv.Value.Nodes.Add(kv.Value.Setter); } } asmNode.UpdateCoverageInfo(); } EndUpdate(); }
private void LoadType(TreeNode parentNode, Type type) { if (!type.IsEnum && !type.IsInterface && !type.IsValueType && type.IsClass) { TreeNode node; if (type.IsPublic) { node = new ClassTreeNode(type, ClassType.Class, Access.Public); parentNode.Nodes.Add(node); } else if (type.IsNestedPrivate) { node = new ClassTreeNode(type, ClassType.Class, Access.Private); parentNode.Nodes.Add(node); } else if (type.IsNestedFamORAssem) { node = new ClassTreeNode(type, ClassType.Class, Access.Internal); parentNode.Nodes.Add(node); } else { // It must be Protected. node = new ClassTreeNode(type, ClassType.Class, Access.Protected); parentNode.Nodes.Add(node); } //TreeNode node = (treeView1.Nodes.Find(type.FullName, true))[0]; foreach (Type ntd in type.GetNestedTypes()) { LoadType(node, ntd); } foreach (MethodInfo md in type.GetMethods()) { LoadMethod(node, md); } foreach (Type ntd in type.GetInterfaces()) { LoadImplementedInterface(node, ntd); } foreach (EventInfo ed in type.GetEvents()) { LoadEvent(node, ed); } foreach (PropertyInfo pd in type.GetProperties()) { LoadProperty(node, pd); } foreach (FieldInfo fd in type.GetFields()) { LoadField(node, fd); } } else if (type.IsEnum) { LoadEnum(parentNode, type); } else if (type.IsInterface) { LoadInterface(parentNode, type.GetElementType()); } else if (type.IsValueType) { LoadStruct(parentNode, type); } else { throw new Exception(); } }