RenameNamespaceCommand(string newName, NamespaceTreeNode nsNode) { this.newName = newName; this.origName = nsNode.Name; this.nsNode = nsNode; this.existingNsNode = (NamespaceTreeNode)nsNode.Parent.Children.FirstOrDefault(a => a is NamespaceTreeNode && AssemblyTreeNode.NamespaceStringEqualsComparer.Equals(newName, ((NamespaceTreeNode)a).Name)); var module = ILSpyTreeNode.GetModule(nsNode); Debug.Assert(module != null); if (module == null) { throw new InvalidOperationException(); } this.origParentNode = (ILSpyTreeNode)nsNode.Parent; this.origParentChildIndex = this.origParentNode.Children.IndexOf(nsNode); Debug.Assert(this.origParentChildIndex >= 0); if (this.origParentChildIndex < 0) { throw new InvalidOperationException(); } // Make sure the exact same namespace names are restored if we undo. The names are UTF8 // strings, but not necessarily canonicalized if it's an obfuscated assembly. nsNode.EnsureChildrenFiltered(); this.origChildren = nsNode.Children.Cast <TypeTreeNode>().ToArray(); this.typeNamespaces = new UTF8String[nsNode.Children.Count]; for (int i = 0; i < this.typeNamespaces.Length; i++) { this.typeNamespaces[i] = origChildren[i].TypeDefinition.Namespace; } this.typeRefInfos = GetTypeRefInfos(module, new[] { nsNode }); }
public void Add(NamespaceTreeNode node) { if (Children == null) { Children = new SortedList <string, NamespaceTreeNode>(StringComparer.OrdinalIgnoreCase); } Children.Add(node.Title, node); }
public NamespaceTreeNode(string name, NamespaceTreeNode parent, int offsetFromRoot) { this.LeafName = name; this.Parent = parent; this.OriginalDefinitions = new List <Namespace>(); this.Children = new Dictionary <string, NamespaceTreeNode>(); this.NamesByLocale = new Dictionary <Locale, string>(); this.OffsetFromRoot = offsetFromRoot; }
private NamespaceTreeNode GetOrCreateNode(NamespaceTreeNode node, string[] parts, int index) { if (index == parts.Length) { return(node); } node = node.GetOrCreate(parts[index]); return(GetOrCreateNode(node, parts, ++index)); }
private void Insert(NamespaceTreeNode root, DeclaredSymbolInfo type) { var namespaceString = type.GetNamespace(); var parts = namespaceString.Split(new[] { '.' }, StringSplitOptions.RemoveEmptyEntries); var nodeWhereToInsert = GetOrCreateNode(root, parts, 0); // { is to sort types after namespaces var inserted = nodeWhereToInsert.GetOrCreate("{" + type.Name); inserted.TypeDeclaration = type; }
private NamespaceTreeNode GetOrCreateNode(NamespaceTreeNode node, string[] parts, int index) { if (index == parts.Length) { return node; } node = node.GetOrCreate(parts[index]); return GetOrCreateNode(node, parts, ++index); }
public NamespaceTreeNode ConstructTree(IEnumerable<DeclaredSymbolInfo> types) { var root = new NamespaceTreeNode(""); foreach (var type in types) { Insert(root, type); } return root; }
void HandleCommandLineArgumentsAfterShowList(CommandLineArguments args) { if (args.NavigateTo != null) { bool found = false; if (args.NavigateTo.StartsWith("N:", StringComparison.Ordinal)) { string namespaceName = args.NavigateTo.Substring(2); foreach (LoadedAssembly asm in commandLineLoadedAssemblies) { AssemblyTreeNode asmNode = assemblyListTreeNode.FindAssemblyNode(asm); if (asmNode != null) { NamespaceTreeNode nsNode = asmNode.FindNamespaceNode(namespaceName); if (nsNode != null) { found = true; SelectNode(nsNode); break; } } } } else { foreach (LoadedAssembly asm in commandLineLoadedAssemblies) { ModuleDefinition def = asm.ModuleDefinition; if (def != null) { MemberReference mr = XmlDocKeyProvider.FindMemberByKey(def, args.NavigateTo); if (mr != null) { found = true; JumpToReference(mr); break; } } } } if (!found) { AvalonEditTextOutput output = new AvalonEditTextOutput(); output.Write(string.Format("Cannot find '{0}' in command line specified assemblies.", args.NavigateTo)); decompilerTextView.ShowText(output); } } else if (commandLineLoadedAssemblies.Count == 1) { // NavigateTo == null and an assembly was given on the command-line: // Select the newly loaded assembly JumpToReference(commandLineLoadedAssemblies[0].ModuleDefinition); } commandLineLoadedAssemblies.Clear(); // clear references once we don't need them anymore }
public NamespaceTreeNode ConstructTree(IEnumerable <DeclaredSymbolInfo> types) { var root = new NamespaceTreeNode(""); foreach (var type in types) { Insert(root, type); } return(root); }
public TokenizerContext Tokenize(HeaderDefinition header) { _context = new TokenizerContext(); NamespaceTreeNode namespaceTree = HeaderNamespaceTree.GetTree(header); IToken namespaceToken = TokenizeNamespace(namespaceTree); _context.Add(namespaceToken); return(_context); }
private void WriteFile(string assemblyName, IEnumerable <DeclaredSymbolInfo> types, string rootPath, string pathPrefix) { var fileName = Path.Combine(rootPath, Constants.Namespaces); NamespaceTreeNode root = ConstructTree(types); using (var sw = new StreamWriter(fileName)) { Markup.WriteNamespaceExplorerPrefix(assemblyName, sw, pathPrefix); WriteChildren(root, sw, pathPrefix); Markup.WriteNamespaceExplorerSuffix(sw); } }
private void WriteChildren(NamespaceTreeNode node, StreamWriter sw, string pathPrefix) { if (node.Children == null) { return; } foreach (var child in node.Children) { WriteChild(child.Value, sw, pathPrefix); } }
private void GenerateLookupForLocaleImpl( Dictionary <string, NamespaceReferenceTemplate> lookup, Locale locale, NamespaceTreeNode node, string namespaceBuilder) { string localizedName = null; Namespace representative = null; foreach (Namespace ns in node.OriginalDefinitions) { if (ns.NamesByLocale.ContainsKey(locale)) { string newLocalizedName = ns.NamesByLocale[locale][node.OffsetFromRoot - ns.NestDepth]; if (localizedName != null && newLocalizedName != localizedName) { // TODO: this error message is not very helpful // https://github.com/blakeohare/crayon/issues/304 throw new ParserException(ns, "This namespace definition has a different localized name somewhere else."); } localizedName = newLocalizedName; representative = ns; } } if (node.LeafName != "*") { if (localizedName == null) { localizedName = node.LeafName; } namespaceBuilder = namespaceBuilder == null ? localizedName : (namespaceBuilder + "." + localizedName); } if (namespaceBuilder != null) { lookup[namespaceBuilder] = new NamespaceReferenceTemplate() { Name = namespaceBuilder, OriginalNamespace = representative ?? node.OriginalDefinitions[0], OriginalNamespaceDepthClipping = namespaceBuilder.Split('.').Length, }; } foreach (NamespaceTreeNode child in node.Children.Values) { this.GenerateLookupForLocaleImpl(lookup, locale, child, namespaceBuilder); } }
void HandleCommandLineArgumentsAfterShowList(CommandLineArguments args) { if (args.NavigateTo != null) { bool found = false; if (args.NavigateTo.StartsWith("N:", StringComparison.Ordinal)) { string namespaceName = args.NavigateTo.Substring(2); foreach (LoadedAssembly asm in commandLineLoadedAssemblies) { AssemblyTreeNode asmNode = assemblyListTreeNode.FindAssemblyNode(asm); if (asmNode != null) { NamespaceTreeNode nsNode = asmNode.FindNamespaceNode(namespaceName); if (nsNode != null) { found = true; SelectNode(nsNode); break; } } } } else { foreach (LoadedAssembly asm in commandLineLoadedAssemblies) { AssemblyDefinition def = asm.AssemblyDefinition; if (def != null) { MemberReference mr = XmlDocKeyProvider.FindMemberByKey(def.MainModule, args.NavigateTo); if (mr != null) { found = true; JumpToReference(mr); break; } } } } if (!found) { AvalonEditTextOutput output = new AvalonEditTextOutput(); output.Write("Cannot find " + args.NavigateTo); decompilerTextView.ShowText(output); } } commandLineLoadedAssemblies.Clear(); // clear references once we don't need them anymore }
private void GenerateLookupForLocaleImpl( Dictionary <string, NamespaceReferenceTemplate> lookup, Locale locale, NamespaceTreeNode node, string namespaceBuilder) { string localizedName = null; Namespace representative = null; foreach (Namespace ns in node.OriginalDefinitions) { if (ns.NamesByLocale.ContainsKey(locale)) { string newLocalizedName = ns.NamesByLocale[locale][node.OffsetFromRoot - ns.NestDepth]; if (localizedName != null && newLocalizedName != localizedName) { TODO.ThisErrorMessageIsNotVeryHelpeful(); throw new ParserException(ns.FirstToken, "This namespace definition has a different localized name somewhere else."); } localizedName = newLocalizedName; representative = ns; } } if (node.LeafName != "*") { if (localizedName == null) { localizedName = node.LeafName; } namespaceBuilder = namespaceBuilder == null ? localizedName : (namespaceBuilder + "." + localizedName); } if (namespaceBuilder != null) { lookup[namespaceBuilder] = new NamespaceReferenceTemplate() { Name = namespaceBuilder, OriginalNamespace = representative ?? node.OriginalDefinitions[0], }; } foreach (NamespaceTreeNode child in node.Children.Values) { this.GenerateLookupForLocaleImpl(lookup, locale, child, namespaceBuilder); } }
public NamespaceTreeNodeCreator(string ns, AssemblyTreeNode asmNode) { Debug.Assert(asmNode.IsModule); if (!asmNode.IsModule) { throw new InvalidOperationException(); } this.asmNode = asmNode; this.nsNode = asmNode.FindNamespaceNode(ns); if (this.nsNode == null) { this.nsNode = new NamespaceTreeNode(ns); this.nsNodeCreated = true; } }
private void LoadModule(TreeNode parent, Module md) { ModuleTreeNode tn = new ModuleTreeNode(md); parent.Nodes.Add(tn); foreach (Type t in md.GetTypes()) { if (!tn.Namespaces.ContainsKey((t.Namespace == null ? "-" : t.Namespace))) { TreeNode tnd = new NamespaceTreeNode((t.Namespace == null ? "-" : t.Namespace)); tn.Nodes.Add(tnd); tn.Namespaces.Add((t.Namespace == null ? "-" : t.Namespace), tnd); } LoadType(tn.Namespaces[(t.Namespace == null ? "-" : t.Namespace)], t); } }
/// <summary> /// Sorts the children of a NamespaceTreeNode /// </summary> /// <param name="node"></param> public static void SortChildren(NamespaceTreeNode node) { //Groups the children by type and performs ordering var ordered = node.Children .OrderBy(x => x.Text.ToString()) .ToArray(); //Clears the children node.Children.Clear(); //Readds the children foreach (var x in ordered) { node.Children.Add(x); } }
public NamespaceTreeNode GetOrCreate(string title) { if (Children == null) { Children = new SortedList <string, NamespaceTreeNode>(StringComparer.OrdinalIgnoreCase); } // need to try finding both folders and files string other = title.StartsWith("{") ? title.TrimStart('{') : "{" + title; if (!Children.TryGetValue(title, out NamespaceTreeNode result) && !Children.TryGetValue(other, out result)) { result = new NamespaceTreeNode(title); Children.Add(title, result); } return(result); }
private BlockToken TokenizeNamespace(NamespaceTreeNode node) { string name; if (node.Children.Count == 1 && node.Nodes.Count == 0) { var child = node.Children[0]; if (node.Namespace.IsGlobal) { name = child.Namespace.Name; } else { name = $"{node.Namespace.Name}.{child.Namespace.Name}"; } node = child; } else { name = node.Namespace.Name; } LineToken header = new LineToken($"namespace {name}"); var children = new List <IToken>(); foreach (ModelNodeDefinition childNode in node.Nodes) { IToken childToken = TokenizeNode(childNode); children.Add(childToken); } foreach (var childNamespace in node.Children) { IToken childNamespaceToken = TokenizeNamespace(childNamespace); children.Add(childNamespaceToken); } BlockToken @namespace = new BlockToken(header, children); return(@namespace); }
private void WriteChild(NamespaceTreeNode node, StreamWriter sw, string pathPrefix) { if (node.TypeDeclaration != null) { WriteType(node.TypeDeclaration, sw, node.Children != null ? "folderTitle" : "typeTitle", pathPrefix); } else { WriteNamespace(node.Title, sw); } if (node.Children != null) { sw.WriteLine("<div class=\"folder\">"); WriteChildren(node, sw, pathPrefix); sw.Write("</div>"); } sw.WriteLine(); }
protected override IMetadataTokenProvider ImportCore(MemberImportingOptions options, SharpTreeNode node) { //Checks that the task hasn't been canceled options.CancellationToken.ThrowIfCancellationRequested(); //Checks if the destination is a module or a type if (Destination is ModuleDefinition) { //Destination var dest = (ModuleDefinition)Destination; dest.Types.Add(typeClone); //Finds the correct namespace var ns = typeClone.Namespace; var moduleNode = Helpers.Tree.GetModuleNode((ModuleDefinition)Destination); var nsNode = moduleNode.Children.EnsureLazyChildren().OfType <NamespaceTreeNode>().FirstOrDefault(x => x.Name == ns); if (nsNode != null) { nsNode.AddChildAndColorAncestors(new ILEditTreeNode(typeClone, false)); } else { nsNode = new NamespaceTreeNode(typeClone.Namespace) { Foreground = GlobalContainer.ModifiedNodesBrush }; nsNode.Children.Add(new ILEditTreeNode(typeClone, false)); moduleNode.AddChildAndColorAncestors(nsNode); } } else { //Destination var dest = (TypeDefinition)Destination; dest.NestedTypes.Add(typeClone); node.AddChildAndColorAncestors(new ILEditTreeNode(typeClone, false)); } //Return return(typeClone); }
void SelectLinqPadQueryNode() { var root = ((AssemblyTreeNode)treeView.Items[0]); root.IsExpanded = true; var namespaceNodes = (Dictionary <string, NamespaceTreeNode>) root.GetType().GetField("namespaces", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(root); NamespaceTreeNode linqPadNamespaceNode = namespaceNodes[String.Empty]; linqPadNamespaceNode.IsExpanded = true; string linqpadGeneratedClassName = this.GetLinqPadClassName(linqPadNamespaceNode); var queryNode = (TypeTreeNode)linqPadNamespaceNode.Children.First(c => Equals(c.Text, linqpadGeneratedClassName)); queryNode.IsExpanded = true; treeView.SelectedItems.Add(queryNode); }
internal static void RemoveAssy(Assembly assy) { // Remove any empty namespaces for (int i = 0; i < _controlTree.Nodes.Count;) { NamespaceTreeNode n = (NamespaceTreeNode)_controlTree.Nodes[i]; if (!n.RemoveAssy(assy)) { _controlTree.Nodes.Remove(n); } else { i++; } } lock (_assemblies) { if (_assemblies[assy] != null) { _assemblies.Remove(assy); } } }
private static TreeNode GetNamespaceNode(AssemblyTreeNode asmNode, TypedefEntry iClass) { var names = Types.GetNamespaceChain(iClass.Name); TreeNode parentNode = asmNode; for (var i = 0; i < names.Length - 1; ++i) { var nextNode = FindNamespaceNode(parentNode.Nodes, names[i]); if (nextNode == null) { nextNode = new NamespaceTreeNode(asmNode.Assembly, names[i]) { NamespacePath = string.Join(".", names, 0, i + 1) }; parentNode.Nodes.Add(nextNode); } parentNode = nextNode; } return parentNode; }
void HandleCommandLineArgumentsAfterShowList(CommandLineArguments args) { // if a SaveDirectory is given, do not start a second concurrent decompilation // by executing JumpoToReference (leads to https://github.com/icsharpcode/ILSpy/issues/710) if (!string.IsNullOrEmpty(args.SaveDirectory)) { foreach (var x in commandLineLoadedAssemblies) { x.ContinueWhenLoaded((Task <ModuleDefinition> moduleTask) => { OnExportAssembly(moduleTask, args.SaveDirectory); }, TaskScheduler.FromCurrentSynchronizationContext()); } } else if (args.NavigateTo != null) { bool found = false; if (args.NavigateTo.StartsWith("N:", StringComparison.Ordinal)) { string namespaceName = args.NavigateTo.Substring(2); foreach (LoadedAssembly asm in commandLineLoadedAssemblies) { AssemblyTreeNode asmNode = assemblyListTreeNode.FindAssemblyNode(asm); if (asmNode != null) { NamespaceTreeNode nsNode = asmNode.FindNamespaceNode(namespaceName); if (nsNode != null) { found = true; SelectNode(nsNode); break; } } } } else { foreach (LoadedAssembly asm in commandLineLoadedAssemblies) { ModuleDefinition def = asm.ModuleDefinition; if (def != null) { MemberReference mr = XmlDocKeyProvider.FindMemberByKey(def, args.NavigateTo); if (mr != null) { found = true; JumpToReference(mr); break; } } } } if (!found) { AvalonEditTextOutput output = new AvalonEditTextOutput(); output.Write(string.Format("Cannot find '{0}' in command line specified assemblies.", args.NavigateTo)); decompilerTextView.ShowText(output); } } else if (commandLineLoadedAssemblies.Count == 1) { // NavigateTo == null and an assembly was given on the command-line: // Select the newly loaded assembly JumpToReference(commandLineLoadedAssemblies[0].ModuleDefinition); } if (args.Search != null) { SearchPane.Instance.SearchTerm = args.Search; SearchPane.Instance.Show(); } commandLineLoadedAssemblies.Clear(); // clear references once we don't need them anymore }
public void Add(NamespaceTreeNode node) { if (Children == null) { Children = new SortedList<string, NamespaceTreeNode>(StringComparer.OrdinalIgnoreCase); } Children.Add(node.Title, node); }
public void OnNamespace(NamespaceTreeNode node) { Level = 0; }
public NamespaceTreeNode GetOrCreate(string title) { if (Children == null) { Children = new SortedList<string, NamespaceTreeNode>(StringComparer.OrdinalIgnoreCase); } NamespaceTreeNode result = null; // need to try finding both folders and files string other = title.StartsWith("{") ? title.TrimStart('{') : "{" + title; if (!Children.TryGetValue(title, out result) && !Children.TryGetValue(other, out result)) { result = new NamespaceTreeNode(title); Children.Add(title, result); } return result; }
void CreateUI(ITextOutput output, object o, bool includeNamespace) { var ns = o as NamespaceSearchResult; if (ns != null) { NamespaceTreeNode.Write(output, ns.Namespace); return; } var td = o as TypeDef; if (td != null) { Debug.Assert(Language != null); Language.TypeToString(output, td, includeNamespace); return; } var md = o as MethodDef; if (md != null) { output.Write(IdentifierEscaper.Escape(md.Name), TextTokenHelper.GetTextTokenType(md)); return; } var fd = o as FieldDef; if (fd != null) { output.Write(IdentifierEscaper.Escape(fd.Name), TextTokenHelper.GetTextTokenType(fd)); return; } var pd = o as PropertyDef; if (pd != null) { output.Write(IdentifierEscaper.Escape(pd.Name), TextTokenHelper.GetTextTokenType(pd)); return; } var ed = o as EventDef; if (ed != null) { output.Write(IdentifierEscaper.Escape(ed.Name), TextTokenHelper.GetTextTokenType(ed)); return; } var asm = o as AssemblyDef; if (asm != null) { Write(output, asm); return; } var mod = o as ModuleDef; if (mod != null) { output.Write(mod.FullName, TextTokenType.Module); return; } var asmRef = o as AssemblyRef; if (asmRef != null) { Write(output, asmRef); return; } var modRef = o as ModuleRef; if (modRef != null) { output.Write(modRef.FullName, TextTokenType.Module); return; } // non-.NET file var loadedAsm = o as LoadedAssembly; if (loadedAsm != null) { output.Write(loadedAsm.ShortName, TextTokenType.Text); return; } var resNode = o as ResourceTreeNode; if (resNode != null) { ResourceTreeNode.WriteFileName(output, resNode.Name); return; } var resElNode = o as ResourceElementTreeNode; if (resElNode != null) { ResourceTreeNode.WriteFileName(output, resElNode.Name); return; } var s = o as string; if (s != null) { output.Write(s, TextTokenType.Text); return; } Debug.Assert(s == null); }
void HandleCommandLineArgumentsAfterShowList(CommandLineArguments args) { if (nugetPackagesToLoad.Count > 0) { LoadAssemblies(nugetPackagesToLoad, commandLineLoadedAssemblies, focusNode: false); nugetPackagesToLoad.Clear(); } if (args.NavigateTo != null) { bool found = false; if (args.NavigateTo.StartsWith("N:", StringComparison.Ordinal)) { string namespaceName = args.NavigateTo.Substring(2); foreach (LoadedAssembly asm in commandLineLoadedAssemblies) { AssemblyTreeNode asmNode = assemblyListTreeNode.FindAssemblyNode(asm); if (asmNode != null) { NamespaceTreeNode nsNode = asmNode.FindNamespaceNode(namespaceName); if (nsNode != null) { found = true; SelectNode(nsNode); break; } } } } else { ITypeReference typeRef = null; IMemberReference memberRef = null; if (args.NavigateTo.StartsWith("T:", StringComparison.Ordinal)) { typeRef = IdStringProvider.ParseTypeName(args.NavigateTo); } else { memberRef = IdStringProvider.ParseMemberIdString(args.NavigateTo); typeRef = memberRef.DeclaringTypeReference; } foreach (LoadedAssembly asm in commandLineLoadedAssemblies) { var module = asm.GetPEFileOrNull(); if (CanResolveTypeInPEFile(module, typeRef, out var typeHandle)) { IEntity mr = null; ICompilation compilation = typeHandle.Kind == HandleKind.ExportedType ? new DecompilerTypeSystem(module, module.GetAssemblyResolver()) : new SimpleCompilation(module, MinimalCorlib.Instance); mr = memberRef == null ? typeRef.Resolve(new SimpleTypeResolveContext(compilation)) as ITypeDefinition : (IEntity)memberRef.Resolve(new SimpleTypeResolveContext(compilation)); if (mr != null && mr.ParentModule.PEFile != null) { found = true; // Defer JumpToReference call to allow an assembly that was loaded while // resolving a type-forwarder in FindMemberByKey to appear in the assembly list. Dispatcher.BeginInvoke(new Action(() => JumpToReference(mr)), DispatcherPriority.Loaded); break; } } } } if (!found) { AvalonEditTextOutput output = new AvalonEditTextOutput(); output.Write(string.Format("Cannot find '{0}' in command line specified assemblies.", args.NavigateTo)); decompilerTextView.ShowText(output); } } else if (commandLineLoadedAssemblies.Count == 1) { // NavigateTo == null and an assembly was given on the command-line: // Select the newly loaded assembly JumpToReference(commandLineLoadedAssemblies[0].GetPEFileOrNull()); } if (args.Search != null) { SearchPane.Instance.SearchTerm = args.Search; SearchPane.Instance.Show(); } commandLineLoadedAssemblies.Clear(); // clear references once we don't need them anymore }
/// <summary> /// Fills the given node with the nodes necessary for the preview of the importing. This action requires a call to Scan() /// </summary> /// <param name="root"></param> public void BuildPreviewNodes(SharpTreeNode root) { //Checks that the root node isn't null if (root == null) { throw new ArgumentNullException("root"); } //Checks if Scan() has already been called if (!Scanned) { throw new InvalidOperationException("Cannot build preview nodes before a call to Scan()"); } //Gets the members needed by the import list and by this instance var members = GetMembersForPreview().ToArray(); //Checks that there's at least one element if (members.Length == 0) { return; } //Builds up to the type nodes var typeNodes = BuildTypeNodes(members); //Lists of the assembly and module nodes (needed for preview of assembly references) var asmNodes = new List <ILEditTreeNode>(); var moduleNodes = new List <ILEditTreeNode>(); //Groups by assembly, module and then namespace var grouped = typeNodes.GroupBy(x => x.Member.Module) .OrderBy(x => x.Key.Name) .Select(x => x.OrderBy(y => y.Text.ToString()).GroupBy(y => ((TypeDefinition)y.Member).Namespace).OrderBy(y => y.Key).GroupBy(y => x.Key).ElementAt(0)) .GroupBy(x => x.Key.Assembly) .OrderBy(x => x.Key.Name.Name) .Select(x => { //Assembly node var asmNode = new ILEditTreeNode(x.Key, true) { IsExpanded = true, Foreground = GlobalContainer.NormalNodesBrush }; foreach (var m in x) { //Module node var moduleNode = new ILEditTreeNode(m.Key, true) { IsExpanded = true, Foreground = GlobalContainer.NormalNodesBrush }; foreach (var n in m) { //Namespace node var namespaceNode = new NamespaceTreeNode(n.Key) { IsExpanded = true, Foreground = GlobalContainer.NormalNodesBrush }; foreach (var t in n) { namespaceNode.Children.Add(t); } moduleNode.Children.Add(namespaceNode); } moduleNodes.Add(moduleNode); asmNode.Children.Add(moduleNode); } asmNodes.Add(asmNode); return(asmNode); }); //Clears the root root.Children.Clear(); //Adds the nodes to the root foreach (var x in grouped) { root.Children.Add(x); } //Groups the references by module var references = members.OfType <Importers.AssemblyReferenceImporter>() .GroupBy( x => (ModuleDefinition)x.Destination, x => (AssemblyNameReference)x.Member ); //Creates the references nodes foreach (var refs in references) { //Creates and populates the references node var refFolder = new ILEditTreeNode.ReferenceFolderNode(); foreach (var r in refs) { refFolder.Children.Add(new ILEditTreeNode(r, true) { IsExpanded = true, Foreground = GlobalContainer.ModifiedNodesBrush }); } //Finds the module node to add to var moduleNode = moduleNodes.FirstOrDefault(x => (ModuleDefinition)x.TokenProvider == refs.Key); if (moduleNode != null) { //Adds the references to the module node moduleNode.Children.Insert(0, refFolder); } else { //Finds or creates the assembly node var asmNode = asmNodes.FirstOrDefault(x => (AssemblyDefinition)x.TokenProvider == refs.Key.Assembly); if (asmNode != null) { //Adds a module node to the assembly asmNode.Children.Add(new ILEditTreeNode(refs.Key, true) { IsExpanded = true, Foreground = GlobalContainer.NormalNodesBrush, Children = { refFolder } }); } else { //Creates the nodes and adds it to the root root.Children.Add(new ILEditTreeNode(refs.Key.Assembly, true) { IsExpanded = true, Foreground = GlobalContainer.NormalNodesBrush, Children = { new ILEditTreeNode(refs.Key, true) { IsExpanded = true, Foreground = GlobalContainer.NormalNodesBrush, Children = { refFolder } } } }); } } } }
private static TreeNode GetNamespaceNode(TreeNode asmNode, IClass iClass) { INamespace[] names = iClass.GetNamespaceChain(); TreeNode parentNode = asmNode; for (int i = 0; i < names.Length; ++i) { NamespaceTreeNode nextNode = FindNamespaceNode(parentNode.Nodes, names[i]); if (nextNode == null) { nextNode = new NamespaceTreeNode(names[i]); parentNode.Nodes.Add(nextNode); } parentNode = nextNode; } return parentNode; }
void HandleCommandLineArgumentsAfterShowList(CommandLineArguments args) { if (nugetPackagesToLoad.Count > 0) { LoadAssemblies(nugetPackagesToLoad, commandLineLoadedAssemblies, focusNode: false); nugetPackagesToLoad.Clear(); } if (args.NavigateTo != null) { bool found = false; if (args.NavigateTo.StartsWith("N:", StringComparison.Ordinal)) { string namespaceName = args.NavigateTo.Substring(2); foreach (LoadedAssembly asm in commandLineLoadedAssemblies) { AssemblyTreeNode asmNode = assemblyListTreeNode.FindAssemblyNode(asm); if (asmNode != null) { NamespaceTreeNode nsNode = asmNode.FindNamespaceNode(namespaceName); if (nsNode != null) { found = true; SelectNode(nsNode); break; } } } } else { foreach (LoadedAssembly asm in commandLineLoadedAssemblies) { ModuleDefinition def = asm.GetModuleDefinitionOrNull(); if (def != null) { MemberReference mr = XmlDocKeyProvider.FindMemberByKey(def, args.NavigateTo); if (mr != null) { found = true; // Defer JumpToReference call to allow an assembly that was loaded while // resolving a type-forwarder in FindMemberByKey to appear in the assembly list. Dispatcher.UIThread.InvokeAsync(new Action(() => JumpToReference(mr)), DispatcherPriority.Loaded); break; } } } } if (!found) { AvaloniaEditTextOutput output = new AvaloniaEditTextOutput(); output.Write(string.Format("Cannot find '{0}' in command line specified assemblies.", args.NavigateTo)); decompilerTextView.ShowText(output); } } else if (commandLineLoadedAssemblies.Count == 1) { // NavigateTo == null and an assembly was given on the command-line: // Select the newly loaded assembly JumpToReference(commandLineLoadedAssemblies[0].GetModuleDefinitionOrNull()); } if (args.Search != null) { SearchPane.Instance.SearchTerm = args.Search; SearchPane.Instance.Show(); } commandLineLoadedAssemblies.Clear(); // clear references once we don't need them anymore }
protected override void LoadChildren() { ModuleDefinition moduleDefinition = assembly.ModuleDefinition; if (moduleDefinition == null) { // if we crashed on loading, then we don't have any children return; } foreach (NamespaceTreeNode ns in namespaces.Values) { ns.Children.Clear(); } foreach (TypeDefinition type in moduleDefinition.Types.OrderBy(t => t.FullName)) { NamespaceTreeNode ns; if (!namespaces.TryGetValue(type.Namespace, out ns)) { ns = new NamespaceTreeNode(type.Namespace); namespaces[type.Namespace] = ns; } TypeTreeNode node = new TypeTreeNode(type, this); typeDict[type] = node; ns.Children.Add(node); } foreach (NamespaceTreeNode ns in namespaces.Values.OrderBy(n => n.Name)) { if (ns.Children.Count > 0) this.Children.Add(ns); } }
async void NavigateOnLaunch(string navigateTo, string[] activeTreeViewPath, ILSpySettings spySettings, List <LoadedAssembly> relevantAssemblies) { var initialSelection = treeView.SelectedItem; if (navigateTo != null) { bool found = false; if (navigateTo.StartsWith("N:", StringComparison.Ordinal)) { string namespaceName = navigateTo.Substring(2); foreach (LoadedAssembly asm in relevantAssemblies) { AssemblyTreeNode asmNode = assemblyListTreeNode.FindAssemblyNode(asm); if (asmNode != null) { // FindNamespaceNode() blocks the UI if the assembly is not yet loaded, // so use an async wait instead. await asm.GetPEFileAsync().Catch <Exception>(ex => { }); NamespaceTreeNode nsNode = asmNode.FindNamespaceNode(namespaceName); if (nsNode != null) { found = true; if (treeView.SelectedItem == initialSelection) { SelectNode(nsNode); } break; } } } } else if (navigateTo == "none") { // Don't navigate anywhere; start empty. // Used by ILSpy VS addin, it'll send us the real location to navigate to via IPC. found = true; } else { IEntity mr = await Task.Run(() => FindEntityInRelevantAssemblies(navigateTo, relevantAssemblies)); if (mr != null && mr.ParentModule.PEFile != null) { found = true; if (treeView.SelectedItem == initialSelection) { JumpToReference(mr); } } } if (!found && treeView.SelectedItem == initialSelection) { AvalonEditTextOutput output = new AvalonEditTextOutput(); output.Write(string.Format("Cannot find '{0}' in command line specified assemblies.", navigateTo)); decompilerTextView.ShowText(output); } } else if (relevantAssemblies.Count == 1) { // NavigateTo == null and an assembly was given on the command-line: // Select the newly loaded assembly AssemblyTreeNode asmNode = assemblyListTreeNode.FindAssemblyNode(relevantAssemblies[0]); if (asmNode != null && treeView.SelectedItem == initialSelection) { SelectNode(asmNode); } } else if (spySettings != null) { SharpTreeNode node = null; if (activeTreeViewPath?.Length > 0) { foreach (var asm in assemblyList.GetAssemblies()) { if (asm.FileName == activeTreeViewPath[0]) { // FindNodeByPath() blocks the UI if the assembly is not yet loaded, // so use an async wait instead. await asm.GetPEFileAsync().Catch <Exception>(ex => { }); } } node = FindNodeByPath(activeTreeViewPath, true); } if (treeView.SelectedItem == initialSelection) { if (node != null) { SelectNode(node); // only if not showing the about page, perform the update check: await ShowMessageIfUpdatesAvailableAsync(spySettings); } else { AboutPage.Display(decompilerTextView); } } } }
internal static void AddAssy(Assembly assy, ICollection types) { lock (_assemblies) { // Don't add unless the tab is visible, because // the GetTypes() can take a long time (up to 10 // seconds in some cases) bool controlTreeShowing = ComponentInspectorProperties.ShowControlPanel; if (!controlTreeShowing) { _uptodate = false; return; } // Keep track of the assemblies we know about, don't // add the same one twice if (_assemblies[assy] == null) { _assemblies.Add(assy, assy); } else { return; } } if (types == null) { types = AssemblySupport.GetAssyTypes(assy); } foreach (Type t in types) { if (!(typeof(Control).IsAssignableFrom(t))) { continue; } String ns = t.Namespace; if (ns == null) { ns = ""; } bool found = false; NamespaceTreeNode n = null; for (int i = 0; i < _controlTree.Nodes.Count; i++) { n = (NamespaceTreeNode)_controlTree.Nodes[i]; if (n.Namespace.Equals(ns)) { found = true; n.InvalidateNode(); break; } } if (!found) { n = new NamespaceTreeNode(ns); _controlTree.Nodes.Add(n); } n.AddAssy(assy); } }