Example #1
0
 public object Create(IDocumentViewerToolTipProviderContext context, object @ref)
 {
     if (@ref is GenericParam)
     {
         return(Create(context, (GenericParam)@ref));
     }
     if (@ref is IMemberRef)
     {
         return(Create(context, (IMemberRef)@ref));
     }
     if (@ref is Parameter)
     {
         return(Create(context, (Parameter)@ref));
     }
     if (@ref is Local)
     {
         return(Create(context, (Local)@ref));
     }
     if (@ref is OpCode)
     {
         return(Create(context, (OpCode)@ref));
     }
     if (@ref is NamespaceReference)
     {
         return(Create(context, (NamespaceReference)@ref));
     }
     return(null);
 }
        object Create(IDocumentViewerToolTipProviderContext context, GenericParam gp)
        {
            var provider = context.Create();

            provider.SetImage(gp);

            context.Decompiler.WriteToolTip(provider.Output, gp, null);

            provider.CreateNewOutput();
            try {
                var docProvider = XmlDocLoader.LoadDocumentation(gp.Module);
                if (docProvider is not null)
                {
                    if (!provider.Output.WriteXmlDocGeneric(GetDocumentation(docProvider, gp.Owner), gp.Name) && gp.Owner is TypeDef)
                    {
                        // If there's no doc available, use the parent class' documentation if this
                        // is a generic type parameter (and not a generic method parameter).
                        var owner = ((TypeDef)gp.Owner).DeclaringType;
                        while (owner is not null)
                        {
                            if (provider.Output.WriteXmlDocGeneric(GetDocumentation(docProvider, owner), gp.Name))
                            {
                                break;
                            }
                            owner = owner.DeclaringType;
                        }
                    }
                }
            }
            catch (XmlException) {
            }

            return(provider.Create());
        }
Example #3
0
 public object Create(IDocumentViewerToolTipProviderContext context, object @ref)
 {
     if (@ref is GenericParam gp)
     {
         return(Create(context, gp));
     }
     if (@ref is IMemberRef mr)
     {
         return(Create(context, mr));
     }
     if (@ref is Parameter pd)
     {
         return(Create(context, new SourceParameter(pd, pd.Name, pd.Type, SourceVariableFlags.None)));
     }
     if (@ref is SourceParameter p)
     {
         return(Create(context, p));
     }
     if (@ref is SourceLocal l)
     {
         return(Create(context, l));
     }
     if (@ref is OpCode opc)
     {
         return(Create(context, opc));
     }
     if (@ref is NamespaceReference nsr)
     {
         return(Create(context, nsr));
     }
     return(null);
 }
			static object Create(IDocumentViewerToolTipProviderContext context, XmlNamespaceTextViewerReference nsRef) {
				var provider = context.Create();
				provider.Image = DsImages.Namespace;

				var name = nsRef.XmlNamespaceReference.Definition.Name;
				const string prefix = "clr-namespace:";
				if (name.StartsWith(prefix)) {
					name = name.Substring(prefix.Length);
					string assemblyName, @namespace;
					ParseClrNamespace(name, out assemblyName, out @namespace);
					if (assemblyName == null && @namespace == null)
						provider.Output.Write(nsRef.XmlNamespaceReference.Definition.Name);
					else {
						if (!string.IsNullOrEmpty(@namespace))
							provider.Output.WriteNamespace(@namespace);
						if (!string.IsNullOrEmpty(assemblyName)) {
							if (!string.IsNullOrEmpty(@namespace))
								provider.Output.WriteLine();
							provider.Output.Write(BoxedTextColor.Assembly, assemblyName);
						}
					}
				}
				else
					provider.Output.Write(name);

				return provider.Create();
			}
        object Create(IDocumentViewerToolTipProviderContext context, SourceParameter parameter)
        {
            var provider = context.Create();

            provider.SetImage(parameter);

            context.Decompiler.WriteToolTip(provider.Output, parameter);

            provider.CreateNewOutput();
            var method = parameter.Parameter.Method;

            try {
                var docProvider = XmlDocLoader.LoadDocumentation(method.Module);
                if (docProvider is not null)
                {
                    if (!provider.Output.WriteXmlDocParameter(GetDocumentation(docProvider, method), parameter.Name))
                    {
                        var owner = method.DeclaringType;
                        while (owner is not null)
                        {
                            if (provider.Output.WriteXmlDocParameter(GetDocumentation(docProvider, owner), parameter.Name))
                            {
                                break;
                            }
                            owner = owner.DeclaringType;
                        }
                    }
                }
            }
            catch (XmlException) {
            }

            return(provider.Create());
        }
Example #6
0
            static object Create(IDocumentViewerToolTipProviderContext context, XmlNamespaceTextViewerReference nsRef)
            {
                var provider = context.Create();

                provider.Image = DsImages.Namespace;

                var          origName = nsRef.XmlNamespaceReference.Definition?.Name ?? string.Empty;
                var          name     = origName;
                const string prefix   = "clr-namespace:";

                if (name.StartsWith(prefix))
                {
                    name = name.Substring(prefix.Length);
                    ParseClrNamespace(name, out var assemblyName, out var @namespace);
                    if (assemblyName is null && @namespace is null)
                    {
                        provider.Output.Write(origName);
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(@namespace))
                        {
                            provider.Output.WriteNamespace(@namespace);
                        }
                        if (!string.IsNullOrEmpty(assemblyName))
                        {
                            if (!string.IsNullOrEmpty(@namespace))
                            {
                                provider.Output.WriteLine();
                            }
                            provider.Output.Write(BoxedTextColor.Assembly, assemblyName);
                        }
                    }
                }
        public object?Create(IDocumentViewerToolTipProviderContext context, object? @ref)
        {
            switch (@ref)
            {
            case GenericParam gp:
                return(Create(context, gp));

            case IMemberRef mr:
                return(Create(context, mr));

            case Parameter pd:
                return(Create(context, new SourceParameter(pd, pd.Name, pd.Type, SourceVariableFlags.None)));

            case SourceParameter p:
                return(Create(context, p));

            case SourceLocal l:
                return(Create(context, l));

            case OpCode opc:
                return(Create(context, opc));

            case NamespaceReference nsr:
                return(Create(context, nsr));
            }
            return(null);
        }
        object Create(IDocumentViewerToolTipProviderContext context, NamespaceReference nsRef)
        {
            var provider = context.Create();

            provider.SetImage(nsRef);
            context.Decompiler.WriteNamespaceToolTip(provider.Output, nsRef.Namespace);
            return(provider.Create());
        }
 public object Create(IDocumentViewerToolTipProviderContext context, object @ref)
 {
     if (@ref is XmlNamespaceTextViewerReference nsRef)
     {
         return(Create(context, nsRef));
     }
     return(null);
 }
        object Create(IDocumentViewerToolTipProviderContext context, SourceLocal local)
        {
            var provider = context.Create();

            provider.SetImage(local);
            context.Decompiler.WriteToolTip(provider.Output, local);
            return(provider.Create());
        }
Example #11
0
		public object Create(IDocumentViewerToolTipProviderContext context, object @ref) {
			var bref = @ref as BamlToolTipReference;
			if (bref != null) {
				var provider = context.Create();
				provider.Output.Write(BoxedTextColor.Text, bref.String);
				return provider.Create();
			}

			return null;
		}
Example #12
0
            public object Create(IDocumentViewerToolTipProviderContext context, object @ref)
            {
                var nsRef = @ref as XmlNamespaceTextViewerReference;

                if (nsRef != null)
                {
                    return(Create(context, nsRef));
                }
                return(null);
            }
		public object Create(IDocumentViewerToolTipProviderContext context, object @ref) {
			// This reference is added to the "decompiled" code by ModuleChildNode.Decompile()
			var sref = @ref as StringInfoReference;
			if (sref != null) {
				var provider = context.Create();
				provider.Output.Write(BoxedTextColor.String, sref.Message);
				return provider.Create();
			}

			return null;
		}
Example #14
0
        public object?Create(IDocumentViewerToolTipProviderContext context, object? @ref)
        {
            switch (@ref)
            {
            case MnemonicReference mnemonicRef:
                return(Create(context, mnemonicRef));

            default:
                return(null);
            }
        }
Example #15
0
        public object Create(IDocumentViewerToolTipProviderContext context, object @ref)
        {
            if (@ref is BamlToolTipReference bref)
            {
                var provider = context.Create();
                provider.Output.Write(BoxedTextColor.Text, bref.String);
                return(provider.Create());
            }

            return(null);
        }
        public object?Create(IDocumentViewerToolTipProviderContext context, object? @ref)
        {
            // This reference is added to the "decompiled" code by ModuleChildNode.Decompile()
            if (@ref is StringInfoReference sref)
            {
                var provider = context.Create();
                provider.Output.Write(BoxedTextColor.String, sref.Message);
                return(provider.Create());
            }

            return(null);
        }
        static object?Create(IDocumentViewerToolTipProviderContext context, MnemonicReference mnemonicRef)
        {
            var provider = context.Create();

            var opCode = mnemonicRef.Code.ToOpCode();

            provider.Output.Write(BoxedTextColor.Text, $"{dnSpy_Resources.ToolTip_OpCode}: {opCode.ToOpCodeString()}");
            provider.Output.WriteLine();
            provider.Output.Write(BoxedTextColor.Text, $"{dnSpy_Resources.ToolTip_Instruction}: {opCode.ToInstructionString()}");

            return(provider.Create());
        }
Example #18
0
        object Create(IDocumentViewerToolTipProviderContext context, IVariable v, string name)
        {
            var provider = context.Create();

            provider.SetImage(v);

            if (v == null)
            {
                if (name == null)
                {
                    return(null);
                }
                provider.Output.Write(BoxedTextColor.Text, string.Format("(local variable) {0}", name));
                return(provider.Create());
            }

            context.Decompiler.WriteToolTip(provider.Output, v, name);

            provider.CreateNewOutput();
            if (v is Parameter)
            {
                var method = ((Parameter)v).Method;
                try {
                    var docProvider = XmlDocLoader.LoadDocumentation(method.Module);
                    if (docProvider != null)
                    {
                        if (!provider.Output.WriteXmlDocParameter(GetDocumentation(docProvider, method), v.Name))
                        {
                            var owner = method.DeclaringType;
                            while (owner != null)
                            {
                                if (provider.Output.WriteXmlDocParameter(GetDocumentation(docProvider, owner), v.Name))
                                {
                                    break;
                                }
                                owner = owner.DeclaringType;
                            }
                        }
                    }
                }
                catch (XmlException) {
                }
            }

            return(provider.Create());
        }
        object Create(IDocumentViewerToolTipProviderContext context, OpCode opCode)
        {
            var provider = context.Create();

            var    s         = ILLanguageHelper.GetOpCodeDocumentation(opCode);
            string opCodeHex = opCode.Size > 1 ? $"0x{opCode.Value:X4}" : $"0x{opCode.Value:X2}";

            provider.Output.Write(BoxedTextColor.OpCode, opCode.Name);
            provider.Output.WriteSpace();
            provider.Output.Write(BoxedTextColor.Punctuation, "(");
            provider.Output.Write(BoxedTextColor.Number, opCodeHex);
            provider.Output.Write(BoxedTextColor.Punctuation, ")");
            if (s is not null)
            {
                provider.Output.Write(BoxedTextColor.Text, " - ");
                provider.Output.Write(BoxedTextColor.Text, s);
            }

            return(provider.Create());
        }
        object Create(IDocumentViewerToolTipProviderContext context, IMemberRef @ref)
        {
            var provider = context.Create();

            var resolvedRef = Resolve(@ref) ?? @ref;

            provider.SetImage(resolvedRef);
            context.Decompiler.WriteToolTip(provider.Output, @ref, null);
            provider.CreateNewOutput();
            try {
                if (resolvedRef is IMemberDef)
                {
                    var docProvider = XmlDocLoader.LoadDocumentation(resolvedRef.Module);
                    if (docProvider is not null)
                    {
                        provider.Output.WriteXmlDoc(GetDocumentation(docProvider, resolvedRef));
                    }
                }
            }
            catch (XmlException) {
            }

            return(provider.Create());
        }
Example #21
0
        public object?Create(IDocumentViewerToolTipProviderContext context, object? @ref)
        {
            switch (@ref)
            {
            case sbyte value:
                return(CreateSByte(context, value));

            case byte value:
                return(CreateByte(context, value));

            case short value:
                return(CreateInt16(context, value));

            case ushort value:
                return(CreateUInt16(context, value));

            case int value:
                return(CreateInt32(context, value));

            case uint value:
                return(CreateUInt32(context, value));

            case long value:
                return(CreateInt64(context, value));

            case ulong value:
                return(CreateUInt64(context, value));

            case float value:
                return(CreateSingle(context, value));

            case double value:
                return(CreateDouble(context, value));
            }
            return(null);
        }
			public object Create(IDocumentViewerToolTipProviderContext context, object @ref) {
				var nsRef = @ref as XmlNamespaceTextViewerReference;
				if (nsRef != null)
					return Create(context, nsRef);
				return null;
			}
Example #23
0
        object Create(IDocumentViewerToolTipProviderContext context, Local local)
        {
            var name = GetDecompilerLocalName(context.DocumentViewer.Content.MethodDebugInfos, local) ?? local.Name;

            return(Create(context, local, name));
        }
Example #24
0
 object Create(IDocumentViewerToolTipProviderContext context, Parameter p) => Create(context, p, null);