From cb3acffc35b48ac9548944073cee18ba9614f75f Mon Sep 17 00:00:00 2001 From: WMJ Date: Tue, 18 Dec 2018 08:34:52 +0800 Subject: [PATCH] ! Checked parent accessibility of nested types --- Codist/Helpers/CodeAnalysisHelper.Symbol.cs | 12 ++++++++---- Codist/QuickInfo/CSharpQuickInfo.cs | 6 +++--- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/Codist/Helpers/CodeAnalysisHelper.Symbol.cs b/Codist/Helpers/CodeAnalysisHelper.Symbol.cs index fd8278e1..b0e37bfe 100644 --- a/Codist/Helpers/CodeAnalysisHelper.Symbol.cs +++ b/Codist/Helpers/CodeAnalysisHelper.Symbol.cs @@ -174,7 +174,10 @@ static Comparer CreateSymbolComparer() { public static IEnumerable FindDeclarationMatchName(this Compilation compilation, string symbolName, bool fullMatch, bool matchCase, CancellationToken cancellationToken = default) { var filter = CreateNameFilter(symbolName, fullMatch, matchCase); foreach (var type in compilation.GlobalNamespace.GetAllTypes(cancellationToken)) { - if (type.IsAccessible() && filter(type.Name)) { + if (type.IsAccessible(true) == false) { + continue; + } + if (filter(type.Name)) { yield return type; } if (cancellationToken.IsCancellationRequested) { @@ -183,7 +186,7 @@ public static IEnumerable FindDeclarationMatchName(this Compilation com foreach (var member in type.GetMembers()) { if (member.Kind != SymbolKind.NamedType && member.CanBeReferencedByName - && member.IsAccessible() + && member.IsAccessible(false) && filter(member.Name)) { yield return member; } @@ -653,12 +656,13 @@ public static void GoToSource(this SyntaxReference loc) { CodistPackage.DTE.OpenFile(loc.SyntaxTree.FilePath, pos.Line + 1, pos.Character + 1); } - public static bool IsAccessible(this ISymbol symbol) { + public static bool IsAccessible(this ISymbol symbol, bool checkContainingType) { return symbol != null && (symbol.DeclaredAccessibility == Accessibility.Public || symbol.DeclaredAccessibility == Accessibility.Protected || symbol.DeclaredAccessibility == Accessibility.ProtectedOrInternal - || symbol.ContainingAssembly.GetSourceType() != AssemblySource.Metadata); + || symbol.ContainingAssembly.GetSourceType() != AssemblySource.Metadata) + && (checkContainingType == false || symbol.ContainingType == null || symbol.ContainingType.IsAccessible(true)); } #endregion diff --git a/Codist/QuickInfo/CSharpQuickInfo.cs b/Codist/QuickInfo/CSharpQuickInfo.cs index 6f432bf9..74f41c32 100644 --- a/Codist/QuickInfo/CSharpQuickInfo.cs +++ b/Codist/QuickInfo/CSharpQuickInfo.cs @@ -518,7 +518,7 @@ static void ShowNamespaceInfo(IList qiContent, SyntaxNode node, INamespa if (Config.Instance.QuickInfoOptions.MatchFlags(QuickInfoOptions.NamespaceTypes) == false) { return; } - var namespaces = nsSymbol.GetNamespaceMembers().ToImmutableArray().Sort(Comparer.Create((x, y) => String.Compare(x.Name, y.Name))); + var namespaces = nsSymbol.GetNamespaceMembers().ToImmutableArray().Sort(Comparer.Create((x, y) => String.Compare(x.Name, y.Name, StringComparison.Ordinal))); if (namespaces.Length > 0) { var info = new StackPanel(); info.Add(new ThemedTipText("Namespace:", true)); @@ -753,7 +753,7 @@ static StackPanel ShowStringInfo(string sv) { static void ShowAttributes(IList qiContent, ImmutableArray attrs, int position) { var info = new StackPanel().Add(new ThemedTipText("Attribute:", true)); foreach (var item in attrs) { - if (item.AttributeClass.IsAccessible() == false) { + if (item.AttributeClass.IsAccessible(true) == false) { continue; } info.Children.Add(_SymbolFormatter.ToUIText(new ThemedTipText(), item)); @@ -771,7 +771,7 @@ static void ShowBaseType(IList qiContent, ITypeSymbol typeSymbol, int po var info = new ThemedTipText("Base type: ", true) .AddSymbol(baseType, null, _SymbolFormatter.Class); while (Config.Instance.QuickInfoOptions.MatchFlags(QuickInfoOptions.BaseTypeInheritence) && (baseType = baseType.BaseType) != null) { - if (baseType.IsAccessible() && baseType.IsCommonClass() == false) { + if (baseType.IsAccessible(false) && baseType.IsCommonClass() == false) { info.Append(" - ").AddSymbol(baseType, null, _SymbolFormatter.Class); } }