From d420a302ec8dae11aee443ebcbe9ad556529620a Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sun, 17 Feb 2019 08:56:22 +0100 Subject: [PATCH] Reactivate SearchMsdnContextMenuEntry. --- ILSpy/TreeNodes/SearchMsdnContextMenuEntry.cs | 38 +++++++++++-------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/ILSpy/TreeNodes/SearchMsdnContextMenuEntry.cs b/ILSpy/TreeNodes/SearchMsdnContextMenuEntry.cs index 7f10c0dfe..3fdff767c 100644 --- a/ILSpy/TreeNodes/SearchMsdnContextMenuEntry.cs +++ b/ILSpy/TreeNodes/SearchMsdnContextMenuEntry.cs @@ -17,11 +17,11 @@ // DEALINGS IN THE SOFTWARE. using System.Linq; -using System.Diagnostics; +using ICSharpCode.Decompiler.TypeSystem; namespace ICSharpCode.ILSpy.TreeNodes { - /*[ExportContextMenuEntry(Header = "Search MSDN...", Icon = "images/SearchMsdn.png", Order = 9999)] + [ExportContextMenuEntry(Header = "Search MSDN...", Icon = "images/SearchMsdn.png", Order = 9999)] internal sealed class SearchMsdnContextMenuEntry : IContextMenuEntry { private static string msdnAddress = "http://msdn.microsoft.com/en-us/library/{0}"; @@ -47,34 +47,42 @@ namespace ICSharpCode.ILSpy.TreeNodes foreach (var node in context.SelectedTreeNodes) { - var typeNode = node as TypeTreeNode; - if (typeNode != null && !typeNode.IsPublicAPI) + if (node is TypeTreeNode typeNode && !typeNode.IsPublicAPI) return false; - var eventNode = node as EventTreeNode; - if (eventNode != null && (!eventNode.IsPublicAPI || !eventNode.EventDefinition.DeclaringType.IsPublic)) + if (node is EventTreeNode eventNode && (!eventNode.IsPublicAPI || !IsAccessible(eventNode.EventDefinition))) return false; - var fieldNode = node as FieldTreeNode; - if (fieldNode != null && (!fieldNode.IsPublicAPI || !fieldNode.FieldDefinition.DeclaringType.IsPublic)) + if (node is FieldTreeNode fieldNode && (!fieldNode.IsPublicAPI || !IsAccessible(fieldNode.FieldDefinition))) return false; - var propertyNode = node as PropertyTreeNode; - if (propertyNode != null && (!propertyNode.IsPublicAPI || !propertyNode.PropertyDefinition.DeclaringType.IsPublic)) + if (node is PropertyTreeNode propertyNode && (!propertyNode.IsPublicAPI || !IsAccessible(propertyNode.PropertyDefinition))) return false; - var methodNode = node as MethodTreeNode; - if (methodNode != null && (!methodNode.IsPublicAPI || !methodNode.MethodDefinition.DeclaringType.IsPublic)) + if (node is MethodTreeNode methodNode && (!methodNode.IsPublicAPI || !IsAccessible(methodNode.MethodDefinition))) return false; - var namespaceNode = node as NamespaceTreeNode; - if (namespaceNode != null && string.IsNullOrEmpty(namespaceNode.Name)) + if (node is NamespaceTreeNode namespaceNode && string.IsNullOrEmpty(namespaceNode.Name)) return false; } return true; } + bool IsAccessible(IEntity entity) + { + if (entity.DeclaringTypeDefinition == null) + return false; + switch (entity.DeclaringTypeDefinition.Accessibility) { + case Accessibility.Public: + case Accessibility.Protected: + case Accessibility.ProtectedOrInternal: + return true; + default: + return false; + } + } + public void Execute(TextViewContext context) { if (context.SelectedTreeNodes != null) { @@ -108,5 +116,5 @@ namespace ICSharpCode.ILSpy.TreeNodes if (!string.IsNullOrEmpty(address)) MainWindow.OpenLink(address); } - }*/ + } } \ No newline at end of file