Пример #1
0
        private IEntity FindEntityInRelevantAssemblies(string navigateTo, IEnumerable <LoadedAssembly> relevantAssemblies)
        {
            ITypeReference   typeRef   = null;
            IMemberReference memberRef = null;

            if (navigateTo.StartsWith("T:", StringComparison.Ordinal))
            {
                typeRef = IdStringProvider.ParseTypeName(navigateTo);
            }
            else
            {
                memberRef = IdStringProvider.ParseMemberIdString(navigateTo);
                typeRef   = memberRef.DeclaringTypeReference;
            }
            foreach (LoadedAssembly asm in relevantAssemblies.ToList())
            {
                var module = asm.GetPEFileOrNull();
                if (CanResolveTypeInPEFile(module, typeRef, out var typeHandle))
                {
                    ICompilation compilation = typeHandle.Kind == HandleKind.ExportedType
                                                ? new DecompilerTypeSystem(module, module.GetAssemblyResolver())
                                                : new SimpleCompilation(module, MinimalCorlib.Instance);
                    return(memberRef == null
                                                ? typeRef.Resolve(new SimpleTypeResolveContext(compilation)) as ITypeDefinition
                                                : (IEntity)memberRef.Resolve(new SimpleTypeResolveContext(compilation)));
                }
            }
            return(null);
        }
Пример #2
0
        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
        }