提交 e0c54290 编写于 作者: T Tom Meschter

Be careful removing items from rule sets

Fixes #3098.

It is possible to have multiple `<Rule>` elements with the same ID in a
rule set file, so long as they specify the same Action. This is likely
to happen with former FxCop rules--you'll end up with one copy under the
"Microsoft.Analyzers.ManagedCodeAnalysis" analyzer (from FxCop) and one
under "Microsoft.AnalyzerPowerPack.CSharp" (from a Roslyn-based
analyzer).

When the user selects one of these rules in Solution Explorer and sets
the severity to "Default" we need to find each rule with the matching
ID, and remove them all from the rule set file. However, we remove the
rules while we're in the middle of the enumeration, tripping up the
enumerator and leading to `NullReferenceException`s.

The fix is to first flatten the enumeration of items to be removed to a
list, and then remove them.
上级 d1fc6e65
......@@ -169,7 +169,8 @@ private void UpdateRuleSetFile(string pathToRuleSet, ReportDiagnostic value)
var allMatchingRules = ruleSetDocument.Root
.Descendants("Rule")
.Where(r => r.Attribute("Id").Value.Equals(_descriptor.Id));
.Where(r => r.Attribute("Id").Value.Equals(_descriptor.Id))
.ToList();
foreach (var matchingRule in allMatchingRules)
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册