Skip to content

Commit

Permalink
ExportAnalyzerAttribute: Simplify pattern matching and avoid multiple…
Browse files Browse the repository at this point in the history
… enumeration
  • Loading branch information
siegfriedpammer committed Jul 20, 2024
1 parent 427fbcd commit fe87986
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 1 addition & 2 deletions ICSharpCode.ILSpyX/Analyzers/ExportAnalyzerAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ public ExportAnalyzerAttribute() : base("Analyzer", typeof(IAnalyzer))
{
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);
}
Expand Down
4 changes: 3 additions & 1 deletion ILSpy.Tests/Analyzers/ExportAnalyzerAttributeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ public class ExportAnalyzerAttributeTests
[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"));
Expand Down

0 comments on commit fe87986

Please sign in to comment.