From a7ac5423c28aa731c986aebd9b25627b5a82e1fe Mon Sep 17 00:00:00 2001 From: Steve Dunn Date: Wed, 29 May 2024 09:38:38 +0100 Subject: [PATCH] Invert check for langversion as `Preview` is set to `int32.maxvalue -1` --- src/Vogen/ValueObjectGenerator.cs | 2 +- src/Vogen/WriteStaticAbstracts.cs | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/Vogen/ValueObjectGenerator.cs b/src/Vogen/ValueObjectGenerator.cs index 35ee66b58d..e7ed70029a 100644 --- a/src/Vogen/ValueObjectGenerator.cs +++ b/src/Vogen/ValueObjectGenerator.cs @@ -88,7 +88,7 @@ static void Execute( internalDiags.RecordResolvedGlobalConfig(mergedConfig); - WriteStaticAbstracts.WriteIfNeeded(mergedConfig, context, compilation); + WriteStaticAbstracts.WriteInterfacesAndMethodsIfNeeded(mergedConfig, context, compilation); WriteSystemTextJsonConverterFactories.WriteIfNeeded(mergedConfig, workItems, context, compilation); diff --git a/src/Vogen/WriteStaticAbstracts.cs b/src/Vogen/WriteStaticAbstracts.cs index a8ef792bc3..8cf5caa0bf 100644 --- a/src/Vogen/WriteStaticAbstracts.cs +++ b/src/Vogen/WriteStaticAbstracts.cs @@ -7,11 +7,11 @@ namespace Vogen; internal class WriteStaticAbstracts { - public static void WriteIfNeeded(VogenConfiguration? globalConfig, + public static void WriteInterfacesAndMethodsIfNeeded(VogenConfiguration? globalConfig, SourceProductionContext context, Compilation compilation) { - if (compilation is CSharpCompilation { LanguageVersion: < LanguageVersion.CSharp11 }) + if (compilation is not CSharpCompilation { LanguageVersion: >= LanguageVersion.CSharp11 }) { return; } @@ -30,7 +30,7 @@ public static void WriteIfNeeded(VogenConfiguration? globalConfig, {GenerateSource()} """; - + context.AddSource("VogenInterfaces_g.cs", source); string GenerateSource() @@ -75,6 +75,7 @@ string GenerateFactoryMethodsIfNeeded() } } + string GenerateCastingOperatorsIfNeeded() { StringBuilder sb = new StringBuilder(); @@ -131,11 +132,11 @@ public static string WriteHeaderIfNeeded(string precedingText, VoWorkItem item, return string.Empty; } - if (item.LanguageVersion <= LanguageVersion.CSharp11) + if (item.LanguageVersion >= LanguageVersion.CSharp11) { - return string.Empty; + return precedingText + $" IVogen<{tds.Identifier}, {item.UnderlyingTypeFullName}>"; } - return precedingText + $" IVogen<{tds.Identifier}, {item.UnderlyingTypeFullName}>"; + return string.Empty; } }