Пример #1
0
        static FlowDocument CreateTooltipForEntity(IEntity resolved)
        {
            Language currentLanguage        = MainWindow.Instance.CurrentLanguage;
            DocumentationUIBuilder renderer = new DocumentationUIBuilder(new CSharpAmbience(), currentLanguage.SyntaxHighlighting);
            RichText richText = currentLanguage.GetRichTextTooltip(resolved);

            renderer.AddSignatureBlock(richText.Text, richText.ToRichTextModel());
            try {
                if (resolved.ParentModule == null || resolved.ParentModule.PEFile == null)
                {
                    return(null);
                }
                var docProvider = XmlDocLoader.LoadDocumentation(resolved.ParentModule.PEFile);
                if (docProvider != null)
                {
                    string documentation = docProvider.GetDocumentation(resolved.GetIdString());
                    if (documentation != null)
                    {
                        renderer.AddXmlDocumentation(documentation, resolved, ResolveReference);
                    }
                }
            } catch (XmlException) {
                // ignore
            }
            return(renderer.CreateDocument());

            IEntity ResolveReference(string idString)
            {
                return(MainWindow.FindEntityInRelevantAssemblies(idString, MainWindow.Instance.CurrentAssemblyList.GetAssemblies()));
            }
        }
Пример #2
0
 object GenerateTooltip(ReferenceSegment segment)
 {
     if (segment.Reference is ICSharpCode.Decompiler.Disassembler.OpCodeInfo code)
     {
         XmlDocumentationProvider docProvider = XmlDocLoader.MscorlibDocumentation;
         DocumentationUIBuilder   renderer    = new DocumentationUIBuilder(new CSharpAmbience(), MainWindow.Instance.CurrentLanguage.SyntaxHighlighting);
         renderer.AddSignatureBlock($"{code.Name} (0x{code.Code:x})");
         if (docProvider != null)
         {
             string documentation = docProvider.GetDocumentation("F:System.Reflection.Emit.OpCodes." + code.EncodedName);
             if (documentation != null)
             {
                 renderer.AddXmlDocumentation(documentation, null, null);
             }
         }
         return(new FlowDocumentTooltip(renderer.CreateDocument()));
     }
     else if (segment.Reference is IEntity entity)
     {
         return(new FlowDocumentTooltip(CreateTooltipForEntity(entity)));
     }
     else if (segment.Reference is ValueTuple <PEFile, System.Reflection.Metadata.EntityHandle> unresolvedEntity)
     {
         var typeSystem = new DecompilerTypeSystem(unresolvedEntity.Item1, unresolvedEntity.Item1.GetAssemblyResolver(), TypeSystemOptions.Default | TypeSystemOptions.Uncached);
         try {
             IEntity resolved = typeSystem.MainModule.ResolveEntity(unresolvedEntity.Item2);
             if (resolved == null)
             {
                 return(null);
             }
             return(new FlowDocumentTooltip(CreateTooltipForEntity(resolved)));
         } catch (BadImageFormatException) {
             return(null);
         }
     }
     return(null);
 }