提交 41740746 编写于 作者: D David Poeschl

Do not crash the NamingStyleCodeFix when we cannot find the symbol

Fixes #15788

We should always be able to find the symbol that generated this
diagnostic, but this cannot always be done by simply asking for the
declared symbol on the node from the symbol's declaration location.
Issue #16588 is tracking a more complete fix for this that always
successfully finds the symbol.
上级 20c809b3
......@@ -36,6 +36,16 @@ public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
var model = await document.GetSemanticModelAsync(context.CancellationToken).ConfigureAwait(false);
var symbol = model.GetDeclaredSymbol(node, context.CancellationToken);
// TODO: We should always be able to find the symbol that generated this diagnostic,
// but this cannot always be done by simply asking for the declared symbol on the node
// from the symbol's declaration location.
// See https://github.com/dotnet/roslyn/issues/16588
if (symbol == null)
{
return;
}
var fixedNames = style.MakeCompliant(symbol.Name);
foreach (var fixedName in fixedNames)
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册