예제 #1
0
        static void Check(IEntity entity, ITypeResolveContext context, HashSet <string> idStrings)
        {
            string id = IdStringProvider.GetIdString(entity);

            if (!idStrings.Add(id))
            {
                throw new InvalidOperationException("Duplicate ID string " + id);
            }
            IEntity resolvedEntity = IdStringProvider.FindEntity(id, context);

            if (resolvedEntity != entity)
            {
                throw new InvalidOperationException(id);
            }
        }
            bool TryGetDocumentation(IEntity entity, out XElement documentation)
            {
                if (entity is null)
                {
                    documentation = null;
                    return(false);
                }

                if (!documentationProviders.TryGetValue(entity.ParentModule, out IDocumentationProvider documentationProvider))
                {
                    documentationProvider = XmlDocLoader.LoadDocumentation(entity.ParentModule.PEFile);
                    documentationProviders.Add(entity.ParentModule, documentationProvider);
                }

                documentation = ConvertToDocumentation(documentationProvider?.GetDocumentation(entity));

                if (documentation.HasInheritDoc(out XElement inheritDoc))
                {
                    string referenceName = inheritDoc.GetReferenceName();

                    if (referenceName is null)
                    {
                        XElement baseDocumentation = null;
                        if (entity is ITypeDefinition type)
                        {
                            type.GetBaseTypeDefinitions().FirstOrDefault(t => TryGetDocumentation(t, out baseDocumentation));
                        }
                        else
                        {
                            string id = entity.GetIdString().Substring(entity.DeclaringTypeDefinition.GetIdString().Length);
                            entity
                            .DeclaringTypeDefinition
                            .GetBaseTypeDefinitions()
                            .SelectMany(t => t.Members)
                            .FirstOrDefault(e => e.GetIdString().Substring(e.DeclaringTypeDefinition.GetIdString().Length) == id && TryGetDocumentation(e, out baseDocumentation));
                        }

                        documentation = baseDocumentation;
                    }
                    else
                    {
                        return(TryGetDocumentation(IdStringProvider.FindEntity(referenceName, _resolver), out documentation));
                    }
                }

                return(documentation != null);
            }
예제 #3
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
         {
             foreach (LoadedAssembly asm in commandLineLoadedAssemblies)
             {
                 var def = asm.GetPEFileOrNull();
                 if (def != null)
                 {
                     var compilation = new SimpleCompilation(def, MinimalCorlib.Instance);
                     var mr          = IdStringProvider.FindEntity(args.NavigateTo, new SimpleTypeResolveContext(compilation));
                     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.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
 }
 XElement GetDocumentation(string id) => TryGetDocumentation(IdStringProvider.FindEntity(id, _resolver), out XElement documentation) ? documentation : null;