提交 750fb7e0 编写于 作者: M Martin Strecker

Add IsObsolete to ISymbolExtensions and use it.

上级 95d214cb
......@@ -171,16 +171,13 @@ public static bool IsStartingNewWord(SourceText text, int characterPosition, Fun
Workspace workspace, SemanticModel semanticModel, int position, IReadOnlyList<ISymbol> symbols, SupportedPlatformData supportedPlatforms, CancellationToken cancellationToken)
{
var symbol = symbols[0];
if (IsObsolete(symbol))
if (symbol.IsObsolete())
{
// The symbol is obsolete/deprecated. Lets try to find another one that is not and take that instead.
symbol = symbols.FirstOrDefault(s => !IsObsolete(s)) ?? symbol;
// The first symbol is obsolete/deprecated. Lets try to find another one that is not and take that instead.
symbol = symbols.Skip(1).FirstOrDefault(s => !s.IsObsolete()) ?? symbol;
}
return CreateDescriptionAsync(workspace, semanticModel, position, symbol, overloadCount: symbols.Count - 1, supportedPlatforms, cancellationToken);
static bool IsObsolete(ISymbol symbol)
=> symbol.GetAttributes().Any(x => x.AttributeClass.MetadataName == "ObsoleteAttribute");
}
private static void AddOverloadPart(List<TaggedText> textContentBuilder, int overloadCount, bool isGeneric)
......
......@@ -247,7 +247,7 @@ protected void AddCaptures(SyntaxNode syntax)
private async Task AddDescriptionPartAsync(ISymbol symbol)
{
if (symbol.GetAttributes().Any(x => x.AttributeClass.MetadataName == "ObsoleteAttribute"))
if (symbol.IsObsolete())
{
AddDeprecatedPrefix();
}
......
......@@ -749,5 +749,15 @@ private static bool VerifyGetAsyncEnumerator(IMethodSymbol getAsyncEnumerator)
public static bool IsSymbolWithSpecialDiscardName(this ISymbol symbol)
=> symbol.Name.StartsWith("_") &&
(symbol.Name.Length == 1 || uint.TryParse(symbol.Name.Substring(1), out _));
/// <summary>
/// Returns <see langword="true"/>, if the symbol is marked with the <see cref="System.ObsoleteAttribute"/>.
/// </summary>
/// <param name="symbol"></param>
/// <returns><see langword="true"/> if the symbol is marked with the <see cref="System.ObsoleteAttribute"/>.</returns>
public static bool IsObsolete(this ISymbol symbol)
=> symbol.GetAttributes().Any(x =>
x.AttributeClass?.MetadataName == nameof(ObsoleteAttribute) &&
x.AttributeClass?.ContainingNamespace.Name == nameof(System));
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册