Browse Source

ExportAnalyzerAttribute: Simplify pattern matching and avoid multiple enumeration

pull/3243/head
Siegfried Pammer 10 months ago
parent
commit
fe879869c3
  1. 3
      ICSharpCode.ILSpyX/Analyzers/ExportAnalyzerAttribute.cs
  2. 4
      ILSpy.Tests/Analyzers/ExportAnalyzerAttributeTests.cs

3
ICSharpCode.ILSpyX/Analyzers/ExportAnalyzerAttribute.cs

@ -39,8 +39,7 @@ namespace ICSharpCode.ILSpyX.Analyzers @@ -39,8 +39,7 @@ namespace ICSharpCode.ILSpyX.Analyzers
{
foreach (var type in typeof(ExportAnalyzerAttribute).Assembly.GetTypes())
{
var exportAnalyzerAttribute = type.GetCustomAttribute(typeof(ExportAnalyzerAttribute), false) as ExportAnalyzerAttribute;
if (exportAnalyzerAttribute is not null)
if (type.GetCustomAttribute(typeof(ExportAnalyzerAttribute), false) is ExportAnalyzerAttribute exportAnalyzerAttribute)
{
yield return (exportAnalyzerAttribute, type);
}

4
ILSpy.Tests/Analyzers/ExportAnalyzerAttributeTests.cs

@ -30,7 +30,9 @@ namespace ICSharpCode.ILSpy.Tests.Analyzers @@ -30,7 +30,9 @@ namespace ICSharpCode.ILSpy.Tests.Analyzers
[Test]
public void CollectAnalyzers()
{
var analyzerNames = ExportAnalyzerAttribute.GetAnnotatedAnalyzers().Select(analyzer => analyzer.AnalyzerType.Name);
var analyzerNames = ExportAnalyzerAttribute.GetAnnotatedAnalyzers()
.Select(analyzer => analyzer.AnalyzerType.Name)
.ToArray();
Assert.That(analyzerNames.Contains("AttributeAppliedToAnalyzer"));
Assert.That(analyzerNames.Contains("EventImplementedByAnalyzer"));
Assert.That(analyzerNames.Contains("MethodUsedByAnalyzer"));

Loading…
Cancel
Save