From 8b07f20e582aca4d9b04ebebdc0ad5d27c0677e5 Mon Sep 17 00:00:00 2001 From: David Wake <6890281+daviddotcs@users.noreply.github.com> Date: Sun, 10 Apr 2022 18:09:52 +0800 Subject: [PATCH] Add extension to simplify negating an IncrementalValueProvider --- .../IncrementalValueProviderExtensions.cs | 9 +++++++++ src/SafeRouting.Generator/RouteGenerator.cs | 5 +---- 2 files changed, 10 insertions(+), 4 deletions(-) create mode 100644 src/SafeRouting.Generator/IncrementalValueProviderExtensions.cs diff --git a/src/SafeRouting.Generator/IncrementalValueProviderExtensions.cs b/src/SafeRouting.Generator/IncrementalValueProviderExtensions.cs new file mode 100644 index 0000000..0af1b96 --- /dev/null +++ b/src/SafeRouting.Generator/IncrementalValueProviderExtensions.cs @@ -0,0 +1,9 @@ +using Microsoft.CodeAnalysis; + +namespace SafeRouting.Generator; + +public static class IncrementalValueProviderExtensions +{ + public static IncrementalValueProvider Not(this IncrementalValueProvider source) + => source.Select(static (x, _) => !x); +} diff --git a/src/SafeRouting.Generator/RouteGenerator.cs b/src/SafeRouting.Generator/RouteGenerator.cs index aa75527..68dae9e 100644 --- a/src/SafeRouting.Generator/RouteGenerator.cs +++ b/src/SafeRouting.Generator/RouteGenerator.cs @@ -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()); });