Beispiel #1
0
        static TextBlock CreateTextBlockForEntity(IEntity resolved)
        {
            XmlDocRenderer renderer = new XmlDocRenderer();

            renderer.AppendText(MainWindow.Instance.CurrentLanguage.GetTooltip(resolved));
            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.AppendText(Environment.NewLine);
                        renderer.AddXmlDocumentation(documentation);
                    }
                }
            } catch (XmlException) {
                // ignore
            }
            return(renderer.CreateTextBlock());
        }
 private object GenerateTooltip(ReferenceSegment segment)
 {
     if (segment.Reference is Mono.Cecil.Cil.OpCode)
     {
         Mono.Cecil.Cil.OpCode code           = (Mono.Cecil.Cil.OpCode)segment.Reference;
         string encodedName                   = code.Code.ToString();
         string opCodeHex                     = code.Size > 1 ? string.Format("0x{0:x2}{1:x2}", code.Op1, code.Op2) : string.Format("0x{0:x2}", code.Op2);
         XmlDocumentationProvider docProvider = XmlDocLoader.MscorlibDocumentation;
         if (docProvider != null)
         {
             string documentation = docProvider.GetDocumentation("F:System.Reflection.Emit.OpCodes." + encodedName);
             if (documentation != null)
             {
                 XmlDocRenderer renderer = new XmlDocRenderer();
                 renderer.AppendText(string.Format("{0} ({1}) - ", code.Name, opCodeHex));
                 renderer.AddXmlDocumentation(documentation);
                 return(renderer.CreateTextBlock());
             }
         }
         return(string.Format("{0} ({1})", code.Name, opCodeHex));
     }
     else if (segment.Reference is MemberReference)
     {
         MemberReference mr = (MemberReference)segment.Reference;
         // if possible, resolve the reference
         if (mr is TypeReference)
         {
             mr = ((TypeReference)mr).Resolve() ?? mr;
         }
         else if (mr is MethodReference)
         {
             mr = ((MethodReference)mr).Resolve() ?? mr;
         }
         XmlDocRenderer renderer = new XmlDocRenderer();
         renderer.AppendText(MainWindow.Instance.CurrentLanguage.GetTooltip(mr));
         try {
             XmlDocumentationProvider docProvider = XmlDocLoader.LoadDocumentation(mr.Module);
             if (docProvider != null)
             {
                 string documentation = docProvider.GetDocumentation(XmlDocKeyProvider.GetKey(mr));
                 if (documentation != null)
                 {
                     renderer.AppendText(Environment.NewLine);
                     renderer.AddXmlDocumentation(documentation);
                 }
             }
         } catch (XmlException) {
             // ignore
         }
         return(renderer.CreateTextBlock());
     }
     return(null);
 }
Beispiel #3
0
 object GenerateTooltip(ReferenceSegment segment)
 {
     if (segment.Reference is ICSharpCode.Decompiler.Disassembler.OpCodeInfo code)
     {
         XmlDocumentationProvider docProvider = XmlDocLoader.MscorlibDocumentation;
         if (docProvider != null)
         {
             string documentation = docProvider.GetDocumentation("F:System.Reflection.Emit.OpCodes." + code.EncodedName);
             if (documentation != null)
             {
                 XmlDocRenderer renderer = new XmlDocRenderer();
                 renderer.AppendText($"{code.Name} (0x{code.Code:x}) - ");
                 renderer.AddXmlDocumentation(documentation);
                 return(renderer.CreateTextBlock());
             }
         }
         return($"{code.Name} (0x{code.Code:x})");
     }
     else if (segment.Reference is IEntity entity)
     {
         return(CreateTextBlockForEntity(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(CreateTextBlockForEntity(resolved));
         } catch (BadImageFormatException) {
             return(null);
         }
     }
     return(null);
 }
Beispiel #4
0
        void TextViewMouseHover(object sender, MouseEventArgs e)
        {
            TextViewPosition?position = textEditor.TextArea.TextView.GetPosition(e.GetPosition(textEditor.TextArea.TextView) + textEditor.TextArea.TextView.ScrollOffset);

            if (position == null)
            {
                return;
            }
            int offset = textEditor.Document.GetOffset(position.Value.Location);

            if (referenceElementGenerator.References == null)
            {
                return;
            }
            ReferenceSegment seg = referenceElementGenerator.References.FindSegmentsContaining(offset).FirstOrDefault();

            if (seg == null)
            {
                return;
            }
            object content = GenerateTooltip(seg);

            if (tooltip != null)
            {
                tooltip.IsOpen = false;
            }
            if (content != null)
            {
                tooltip = new ToolTip()
                {
                    Content = content, IsOpen = true
                }
            }
            ;
        }

        object GenerateTooltip(ReferenceSegment segment)
        {
            if (segment.Reference is Mono.Cecil.Cil.OpCode)
            {
                Mono.Cecil.Cil.OpCode code           = (Mono.Cecil.Cil.OpCode)segment.Reference;
                string encodedName                   = code.Code.ToString();
                string opCodeHex                     = code.Size > 1 ? string.Format("0x{0:x2}{1:x2}", code.Op1, code.Op2) : string.Format("0x{0:x2}", code.Op2);
                XmlDocumentationProvider docProvider = XmlDocLoader.MscorlibDocumentation;
                if (docProvider != null)
                {
                    string documentation = docProvider.GetDocumentation("F:System.Reflection.Emit.OpCodes." + encodedName);
                    if (documentation != null)
                    {
                        XmlDocRenderer renderer = new XmlDocRenderer();
                        renderer.AppendText(string.Format("{0} ({1}) - ", code.Name, opCodeHex));
                        renderer.AddXmlDocumentation(documentation);
                        return(renderer.CreateTextBlock());
                    }
                }
                return(string.Format("{0} ({1})", code.Name, opCodeHex));
            }
            else if (segment.Reference is MemberReference)
            {
                MemberReference mr = (MemberReference)segment.Reference;
                // if possible, resolve the reference
                if (mr is TypeReference)
                {
                    mr = ((TypeReference)mr).Resolve() ?? mr;
                }
                else if (mr is MethodReference)
                {
                    mr = ((MethodReference)mr).Resolve() ?? mr;
                }
                XmlDocRenderer renderer = new XmlDocRenderer();
                renderer.AppendText(MainWindow.Instance.CurrentLanguage.GetTooltip(mr));
                try {
                    XmlDocumentationProvider docProvider = XmlDocLoader.LoadDocumentation(mr.Module);
                    if (docProvider != null)
                    {
                        string documentation = docProvider.GetDocumentation(XmlDocKeyProvider.GetKey(mr));
                        if (documentation != null)
                        {
                            renderer.AppendText(Environment.NewLine);
                            renderer.AddXmlDocumentation(documentation);
                        }
                    }
                } catch (XmlException) {
                    // ignore
                }
                return(renderer.CreateTextBlock());
            }
            return(null);
        }
Beispiel #5
0
        void TextViewMouseHover(object sender, MouseEventArgs e)
        {
            TextViewPosition?position = GetPositionFromMousePosition();

            if (position == null)
            {
                return;
            }
            int offset = textEditor.Document.GetOffset(position.Value.Location);

            if (referenceElementGenerator.References == null)
            {
                return;
            }
            ReferenceSegment seg = referenceElementGenerator.References.FindSegmentsContaining(offset).FirstOrDefault();

            if (seg == null)
            {
                return;
            }
            object content = GenerateTooltip(seg);

            if (tooltip != null)
            {
                tooltip.IsOpen = false;
            }
            if (content != null)
            {
                tooltip = new ToolTip()
                {
                    Content = content, IsOpen = true
                }
            }
            ;
        }

        object GenerateTooltip(ReferenceSegment segment)
        {
            if (segment.Reference is ICSharpCode.Decompiler.Disassembler.OpCodeInfo code)
            {
                XmlDocumentationProvider docProvider = XmlDocLoader.MscorlibDocumentation;
                if (docProvider != null)
                {
                    string documentation = docProvider.GetDocumentation("F:System.Reflection.Emit.OpCodes." + code.EncodedName);
                    if (documentation != null)
                    {
                        XmlDocRenderer renderer = new XmlDocRenderer();
                        renderer.AppendText($"{code.Name} (0x{code.Code:x}) - ");
                        renderer.AddXmlDocumentation(documentation);
                        return(renderer.CreateTextBlock());
                    }
                }
                return($"{code.Name} (0x{code.Code:x})");
            }
            else if (segment.Reference is IEntity entity)
            {
                return(CreateTextBlockForEntity(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(CreateTextBlockForEntity(resolved));
                } catch (BadImageFormatException) {
                    return(null);
                }
            }
            return(null);
        }