Skip to content

Commit

Permalink
Add extension to simplify negating an IncrementalValueProvider<bool>
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddotcs committed Apr 10, 2022
1 parent d78af0f commit 8b07f20
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Microsoft.CodeAnalysis;

namespace SafeRouting.Generator;

public static class IncrementalValueProviderExtensions
{
public static IncrementalValueProvider<bool> Not(this IncrementalValueProvider<bool> source)
=> source.Select(static (x, _) => !x);
}
5 changes: 1 addition & 4 deletions src/SafeRouting.Generator/RouteGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
var isSupportedLanguageVersionProvider = languageVersionProvider
.Select(static (x, _) => x >= LanguageVersion.CSharp8);

var isUnsupportedLanguageVersionProvider = isSupportedLanguageVersionProvider
.Select(static (x, _) => !x);

context.RegisterConditionalOutput(isUnsupportedLanguageVersionProvider, static context =>
context.RegisterConditionalOutput(isSupportedLanguageVersionProvider.Not(), static context =>
{
context.ReportDiagnostic(Diagnostics.CreateUnsupportedLanguageVersionDiagnostic());
});
Expand Down

0 comments on commit 8b07f20

Please sign in to comment.