提交 4cc6c5e1 编写于 作者: J Jonathon Marolf

Merge pull request #2816 from jmarolf/FixAddRefBehavior

Only return a fix if the assembly identity matches the diagnostic mes…
......@@ -22,7 +22,8 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context)
{
var nodes = FindNodes(root, diagnostic);
var types = GetTypesForNodes(model, nodes, cancellationToken).Distinct();
AssemblyIdentity identity = GetAssemblyIdentity(types);
var message = diagnostic.GetMessage();
AssemblyIdentity identity = GetAssemblyIdentity(types, message);
if (identity != null && !uniqueIdentities.Contains(identity) && !identity.Equals(model.Compilation.Assembly.Identity))
{
uniqueIdentities.Add(identity);
......@@ -97,18 +98,18 @@ private static IEnumerable<ITypeSymbol> GetTypesFromSymbol(ISymbol symbol)
/// so it is safe to assume if this case exists for one of the symbols given
/// it is the assembly we want to add.
/// </summary>
private static AssemblyIdentity GetAssemblyIdentity(IEnumerable<ITypeSymbol> types)
private static AssemblyIdentity GetAssemblyIdentity(IEnumerable<ITypeSymbol> types, string message)
{
foreach (var type in types)
{
var identity = type?.GetBaseTypesAndThis().OfType<IErrorTypeSymbol>().FirstOrDefault()?.ContainingAssembly?.Identity;
if (identity != null)
if (identity != null && message.Contains(identity.ToString()))
{
return identity;
}
identity = type?.AllInterfaces.OfType<IErrorTypeSymbol>().FirstOrDefault()?.ContainingAssembly?.Identity;
if (identity != null)
if (identity != null && message.Contains(identity.ToString()))
{
return identity;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册