From 091d75332a21d1d78320780ca031a54edcfce6c4 Mon Sep 17 00:00:00 2001 From: Alexey Sosnin Date: Thu, 14 Mar 2024 01:50:24 +0300 Subject: [PATCH 1/2] feat: support netstandard2.0 --- N.SourceGenerators.UnionTypes.sln | 7 ++ examples/DataAccess/DataAccess.csproj | 2 +- .../LegacyFramework/LegacyFramework.csproj | 21 ++++ .../Properties/launchSettings.json | 8 ++ examples/LegacyFramework/Result.cs | 19 ++++ .../Extensions/ConditionalSyntaxExtensions.cs | 10 ++ .../Helpers/RoslynUtils.cs | 8 ++ .../Models/UnionType.cs | 4 +- .../N.SourceGenerators.UnionTypes.csproj | 4 +- .../UnionTypesGenerator.Attributes.cs | 44 +++++++- .../UnionTypesGenerator.Converters.cs | 47 ++++---- .../UnionTypesGenerator.EqualityMembers.cs | 12 +-- .../UnionTypesGenerator.Json.cs | 15 +-- .../UnionTypesGenerator.cs | 102 ++++++++++++------ ...er#GenericUnionTypeAttribute.g.verified.cs | 8 ++ ...sonPolymorphicUnionAttribute.g.verified.cs | 6 ++ ...rter#UnionConverterAttribute.g.verified.cs | 10 ++ ...#UnionConverterFromAttribute.g.verified.cs | 2 + ...er#UnionConverterToAttribute.g.verified.cs | 2 + ...Converter#UnionTypeAttribute.g.verified.cs | 14 +++ ...ic#GenericUnionTypeAttribute.g.verified.cs | 8 ++ ...sonPolymorphicUnionAttribute.g.verified.cs | 6 ++ ...stic#UnionConverterAttribute.g.verified.cs | 10 ++ ...#UnionConverterFromAttribute.g.verified.cs | 2 + ...ic#UnionConverterToAttribute.g.verified.cs | 2 + ...iagnostic#UnionTypeAttribute.g.verified.cs | 14 +++ ...er#GenericUnionTypeAttribute.g.verified.cs | 8 ++ ...sonPolymorphicUnionAttribute.g.verified.cs | 6 ++ ...rter#UnionConverterAttribute.g.verified.cs | 10 ++ ...#UnionConverterFromAttribute.g.verified.cs | 2 + ...er#UnionConverterToAttribute.g.verified.cs | 2 + ...Converter#UnionTypeAttribute.g.verified.cs | 14 +++ ...ic#GenericUnionTypeAttribute.g.verified.cs | 8 ++ ...sonPolymorphicUnionAttribute.g.verified.cs | 6 ++ ...stic#UnionConverterAttribute.g.verified.cs | 10 ++ ...#UnionConverterFromAttribute.g.verified.cs | 2 + ...ic#UnionConverterToAttribute.g.verified.cs | 2 + ...iagnostic#UnionTypeAttribute.g.verified.cs | 14 +++ ...er#GenericUnionTypeAttribute.g.verified.cs | 8 ++ ...sonPolymorphicUnionAttribute.g.verified.cs | 6 ++ ...rter#UnionConverterAttribute.g.verified.cs | 10 ++ ...#UnionConverterFromAttribute.g.verified.cs | 2 + ...er#UnionConverterToAttribute.g.verified.cs | 2 + ...Converter#UnionTypeAttribute.g.verified.cs | 14 +++ ...ic#GenericUnionTypeAttribute.g.verified.cs | 8 ++ ...sonPolymorphicUnionAttribute.g.verified.cs | 6 ++ ...stic#UnionConverterAttribute.g.verified.cs | 10 ++ ...#UnionConverterFromAttribute.g.verified.cs | 2 + ...ic#UnionConverterToAttribute.g.verified.cs | 2 + ...iagnostic#UnionTypeAttribute.g.verified.cs | 14 +++ ...er#GenericUnionTypeAttribute.g.verified.cs | 8 ++ ...sonPolymorphicUnionAttribute.g.verified.cs | 6 ++ ...rter#UnionConverterAttribute.g.verified.cs | 10 ++ ...#UnionConverterFromAttribute.g.verified.cs | 2 + ...er#UnionConverterToAttribute.g.verified.cs | 2 + ...Converter#UnionTypeAttribute.g.verified.cs | 14 +++ ...ic#GenericUnionTypeAttribute.g.verified.cs | 8 ++ ...sonPolymorphicUnionAttribute.g.verified.cs | 6 ++ ...stic#UnionConverterAttribute.g.verified.cs | 10 ++ ...#UnionConverterFromAttribute.g.verified.cs | 2 + ...ic#UnionConverterToAttribute.g.verified.cs | 2 + ...iagnostic#UnionTypeAttribute.g.verified.cs | 14 +++ ...cs#GenericUnionTypeAttribute.g.verified.cs | 8 ++ ...sonPolymorphicUnionAttribute.g.verified.cs | 6 ++ ...tics#UnionConverterAttribute.g.verified.cs | 10 ++ ...#UnionConverterFromAttribute.g.verified.cs | 2 + ...cs#UnionConverterToAttribute.g.verified.cs | 2 + ...agnostics#UnionTypeAttribute.g.verified.cs | 14 +++ ...cs#GenericUnionTypeAttribute.g.verified.cs | 8 ++ ...sonPolymorphicUnionAttribute.g.verified.cs | 6 ++ ...tics#UnionConverterAttribute.g.verified.cs | 10 ++ ...#UnionConverterFromAttribute.g.verified.cs | 2 + ...cs#UnionConverterToAttribute.g.verified.cs | 2 + ...agnostics#UnionTypeAttribute.g.verified.cs | 14 +++ ...cs#GenericUnionTypeAttribute.g.verified.cs | 8 ++ ...sonPolymorphicUnionAttribute.g.verified.cs | 6 ++ ...tics#UnionConverterAttribute.g.verified.cs | 10 ++ ...#UnionConverterFromAttribute.g.verified.cs | 2 + ...cs#UnionConverterToAttribute.g.verified.cs | 2 + ...agnostics#UnionTypeAttribute.g.verified.cs | 14 +++ ...cs#GenericUnionTypeAttribute.g.verified.cs | 8 ++ ...sonPolymorphicUnionAttribute.g.verified.cs | 6 ++ ...tics#UnionConverterAttribute.g.verified.cs | 10 ++ ...#UnionConverterFromAttribute.g.verified.cs | 2 + ...cs#UnionConverterToAttribute.g.verified.cs | 2 + ...agnostics#UnionTypeAttribute.g.verified.cs | 14 +++ ...cs#GenericUnionTypeAttribute.g.verified.cs | 8 ++ ...sonPolymorphicUnionAttribute.g.verified.cs | 6 ++ ...tics#UnionConverterAttribute.g.verified.cs | 10 ++ ...#UnionConverterFromAttribute.g.verified.cs | 2 + ...cs#UnionConverterToAttribute.g.verified.cs | 2 + ...agnostics#UnionTypeAttribute.g.verified.cs | 14 +++ ...es#GenericUnionTypeAttribute.g.verified.cs | 8 ++ ...sonPolymorphicUnionAttribute.g.verified.cs | 6 ++ ...aces#UnionConverterAttribute.g.verified.cs | 10 ++ ...#UnionConverterFromAttribute.g.verified.cs | 2 + ...es#UnionConverterToAttribute.g.verified.cs | 2 + ...amespaces#UnionTypeAttribute.g.verified.cs | 14 +++ ...ss#GenericUnionTypeAttribute.g.verified.cs | 8 ++ ...sonPolymorphicUnionAttribute.g.verified.cs | 6 ++ ...lass#UnionConverterAttribute.g.verified.cs | 10 ++ ...#UnionConverterFromAttribute.g.verified.cs | 2 + ...ss#UnionConverterToAttribute.g.verified.cs | 2 + ...ial-class#UnionTypeAttribute.g.verified.cs | 14 +++ ...ct#GenericUnionTypeAttribute.g.verified.cs | 8 ++ ...sonPolymorphicUnionAttribute.g.verified.cs | 6 ++ ...ruct#UnionConverterAttribute.g.verified.cs | 10 ++ ...#UnionConverterFromAttribute.g.verified.cs | 2 + ...ct#UnionConverterToAttribute.g.verified.cs | 2 + ...al-struct#UnionTypeAttribute.g.verified.cs | 14 +++ ...ct#GenericUnionTypeAttribute.g.verified.cs | 8 ++ ...sonPolymorphicUnionAttribute.g.verified.cs | 6 ++ ...ruct#UnionConverterAttribute.g.verified.cs | 10 ++ ...#UnionConverterFromAttribute.g.verified.cs | 2 + ...ct#UnionConverterToAttribute.g.verified.cs | 2 + ...al-struct#UnionTypeAttribute.g.verified.cs | 14 +++ ...ut#GenericUnionTypeAttribute.g.verified.cs | 8 ++ ...sonPolymorphicUnionAttribute.g.verified.cs | 6 ++ ...yout#UnionConverterAttribute.g.verified.cs | 10 ++ ...#UnionConverterFromAttribute.g.verified.cs | 2 + ...ut#UnionConverterToAttribute.g.verified.cs | 2 + ...uctLayout#UnionTypeAttribute.g.verified.cs | 14 +++ ...ss#GenericUnionTypeAttribute.g.verified.cs | 8 ++ ...sonPolymorphicUnionAttribute.g.verified.cs | 6 ++ ...lass#UnionConverterAttribute.g.verified.cs | 10 ++ ...#UnionConverterFromAttribute.g.verified.cs | 2 + ...ss#UnionConverterToAttribute.g.verified.cs | 2 + ...ial-class#UnionTypeAttribute.g.verified.cs | 14 +++ ...ct#GenericUnionTypeAttribute.g.verified.cs | 8 ++ ...sonPolymorphicUnionAttribute.g.verified.cs | 6 ++ ...ruct#UnionConverterAttribute.g.verified.cs | 10 ++ ...#UnionConverterFromAttribute.g.verified.cs | 2 + ...ct#UnionConverterToAttribute.g.verified.cs | 2 + ...al-struct#UnionTypeAttribute.g.verified.cs | 14 +++ ...ct#GenericUnionTypeAttribute.g.verified.cs | 8 ++ ...sonPolymorphicUnionAttribute.g.verified.cs | 6 ++ ...ruct#UnionConverterAttribute.g.verified.cs | 10 ++ ...#UnionConverterFromAttribute.g.verified.cs | 2 + ...ct#UnionConverterToAttribute.g.verified.cs | 2 + ...al-struct#UnionTypeAttribute.g.verified.cs | 14 +++ ...ss#GenericUnionTypeAttribute.g.verified.cs | 8 ++ ...sonPolymorphicUnionAttribute.g.verified.cs | 6 ++ ...lass#UnionConverterAttribute.g.verified.cs | 10 ++ ...#UnionConverterFromAttribute.g.verified.cs | 2 + ...ss#UnionConverterToAttribute.g.verified.cs | 2 + ...ial-class#UnionTypeAttribute.g.verified.cs | 14 +++ ...ct#GenericUnionTypeAttribute.g.verified.cs | 8 ++ ...sonPolymorphicUnionAttribute.g.verified.cs | 6 ++ ...ruct#UnionConverterAttribute.g.verified.cs | 10 ++ ...#UnionConverterFromAttribute.g.verified.cs | 2 + ...ct#UnionConverterToAttribute.g.verified.cs | 2 + ...al-struct#UnionTypeAttribute.g.verified.cs | 14 +++ ...ct#GenericUnionTypeAttribute.g.verified.cs | 8 ++ ...sonPolymorphicUnionAttribute.g.verified.cs | 6 ++ ...ruct#UnionConverterAttribute.g.verified.cs | 10 ++ ...#UnionConverterFromAttribute.g.verified.cs | 2 + ...ct#UnionConverterToAttribute.g.verified.cs | 2 + ...al-struct#UnionTypeAttribute.g.verified.cs | 14 +++ ...es#GenericUnionTypeAttribute.g.verified.cs | 8 ++ ...sonPolymorphicUnionAttribute.g.verified.cs | 6 ++ ...ypes#UnionConverterAttribute.g.verified.cs | 10 ++ ...#UnionConverterFromAttribute.g.verified.cs | 2 + ...es#UnionConverterToAttribute.g.verified.cs | 2 + ...ericTypes#UnionTypeAttribute.g.verified.cs | 14 +++ ...as#GenericUnionTypeAttribute.g.verified.cs | 8 ++ ...sonPolymorphicUnionAttribute.g.verified.cs | 6 ++ ...lias#UnionConverterAttribute.g.verified.cs | 10 ++ ...#UnionConverterFromAttribute.g.verified.cs | 2 + ...as#UnionConverterToAttribute.g.verified.cs | 2 + ...WithAlias#UnionTypeAttribute.g.verified.cs | 14 +++ ...pe#GenericUnionTypeAttribute.g.verified.cs | 8 ++ ...sonPolymorphicUnionAttribute.g.verified.cs | 6 ++ ...Type#UnionConverterAttribute.g.verified.cs | 10 ++ ...#UnionConverterFromAttribute.g.verified.cs | 2 + ...pe#UnionConverterToAttribute.g.verified.cs | 2 + ...UnionType#UnionTypeAttribute.g.verified.cs | 14 +++ ...il#GenericUnionTypeAttribute.g.verified.cs | 8 ++ ...sonPolymorphicUnionAttribute.g.verified.cs | 6 ++ ...Fail#UnionConverterAttribute.g.verified.cs | 10 ++ ...#UnionConverterFromAttribute.g.verified.cs | 2 + ...il#UnionConverterToAttribute.g.verified.cs | 2 + ...esNotFail#UnionTypeAttribute.g.verified.cs | 14 +++ ...te#GenericUnionTypeAttribute.g.verified.cs | 8 ++ ...sonPolymorphicUnionAttribute.g.verified.cs | 6 ++ ...bute#UnionConverterAttribute.g.verified.cs | 10 ++ ...#UnionConverterFromAttribute.g.verified.cs | 2 + ...te#UnionConverterToAttribute.g.verified.cs | 2 + ...Attribute#UnionTypeAttribute.g.verified.cs | 14 +++ ..._0#GenericUnionTypeAttribute.g.verified.cs | 8 ++ ...sonPolymorphicUnionAttribute.g.verified.cs | 6 ++ ...ly_0#UnionConverterAttribute.g.verified.cs | 10 ++ ...#UnionConverterFromAttribute.g.verified.cs | 2 + ..._0#UnionConverterToAttribute.g.verified.cs | 2 + ...ssembly_0#UnionTypeAttribute.g.verified.cs | 14 +++ ..._1#GenericUnionTypeAttribute.g.verified.cs | 8 ++ ...sonPolymorphicUnionAttribute.g.verified.cs | 6 ++ ...ly_1#UnionConverterAttribute.g.verified.cs | 10 ++ ...#UnionConverterFromAttribute.g.verified.cs | 2 + ..._1#UnionConverterToAttribute.g.verified.cs | 2 + ...ssembly_1#UnionTypeAttribute.g.verified.cs | 14 +++ .../TestHelper.cs | 2 +- 201 files changed, 1536 insertions(+), 71 deletions(-) create mode 100644 examples/LegacyFramework/LegacyFramework.csproj create mode 100644 examples/LegacyFramework/Properties/launchSettings.json create mode 100644 examples/LegacyFramework/Result.cs diff --git a/N.SourceGenerators.UnionTypes.sln b/N.SourceGenerators.UnionTypes.sln index ba3addc..aefe706 100644 --- a/N.SourceGenerators.UnionTypes.sln +++ b/N.SourceGenerators.UnionTypes.sln @@ -38,6 +38,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BusinessLogic", "examples\B EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "N.SourceGenerators.UnionTypes.BehaviorTests", "tests\N.SourceGenerators.UnionTypes.BehaviorTests\N.SourceGenerators.UnionTypes.BehaviorTests.csproj", "{5DD23F15-E950-4538-BF17-8BC5A7F4F720}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LegacyFramework", "examples\LegacyFramework\LegacyFramework.csproj", "{E90A05B8-3085-4DC6-857A-5D87ECEBC99B}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -55,6 +57,7 @@ Global {3B72811B-AA6E-4263-B0E9-931648D636BC} = {432FABD2-1B70-4E29-935B-AEE6D93559E2} {007DEABA-55E6-4AF8-95D7-B869D6B46126} = {432FABD2-1B70-4E29-935B-AEE6D93559E2} {5DD23F15-E950-4538-BF17-8BC5A7F4F720} = {08535BFD-5C2B-4D8B-90B7-520C578BA7E4} + {E90A05B8-3085-4DC6-857A-5D87ECEBC99B} = {432FABD2-1B70-4E29-935B-AEE6D93559E2} EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {2C39796B-5B3A-42F9-84DF-0501A44030B7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU @@ -85,5 +88,9 @@ Global {5DD23F15-E950-4538-BF17-8BC5A7F4F720}.Debug|Any CPU.Build.0 = Debug|Any CPU {5DD23F15-E950-4538-BF17-8BC5A7F4F720}.Release|Any CPU.ActiveCfg = Release|Any CPU {5DD23F15-E950-4538-BF17-8BC5A7F4F720}.Release|Any CPU.Build.0 = Release|Any CPU + {E90A05B8-3085-4DC6-857A-5D87ECEBC99B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E90A05B8-3085-4DC6-857A-5D87ECEBC99B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E90A05B8-3085-4DC6-857A-5D87ECEBC99B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E90A05B8-3085-4DC6-857A-5D87ECEBC99B}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal diff --git a/examples/DataAccess/DataAccess.csproj b/examples/DataAccess/DataAccess.csproj index f624d5e..898914a 100644 --- a/examples/DataAccess/DataAccess.csproj +++ b/examples/DataAccess/DataAccess.csproj @@ -1,5 +1,5 @@ - + diff --git a/examples/LegacyFramework/LegacyFramework.csproj b/examples/LegacyFramework/LegacyFramework.csproj new file mode 100644 index 0000000..eb1bbbb --- /dev/null +++ b/examples/LegacyFramework/LegacyFramework.csproj @@ -0,0 +1,21 @@ + + + + netstandard2.0 + + disable + disable + + + + + + + + + Never + Never + true + + + diff --git a/examples/LegacyFramework/Properties/launchSettings.json b/examples/LegacyFramework/Properties/launchSettings.json new file mode 100644 index 0000000..521d6fa --- /dev/null +++ b/examples/LegacyFramework/Properties/launchSettings.json @@ -0,0 +1,8 @@ +{ + "profiles": { + "Debug Generators": { + "commandName": "DebugRoslynComponent", + "targetProject": "LegacyFramework.csproj" + } + } + } \ No newline at end of file diff --git a/examples/LegacyFramework/Result.cs b/examples/LegacyFramework/Result.cs new file mode 100644 index 0000000..ff88056 --- /dev/null +++ b/examples/LegacyFramework/Result.cs @@ -0,0 +1,19 @@ +using N.SourceGenerators.UnionTypes; + +namespace LegacyFramework +{ + public class Foo + { + } + + public class Bar + { + } + + + [UnionType(typeof(Foo))] + [UnionType(typeof(Bar))] + public partial class Result + { + } +} \ No newline at end of file diff --git a/src/N.SourceGenerators.UnionTypes/Extensions/ConditionalSyntaxExtensions.cs b/src/N.SourceGenerators.UnionTypes/Extensions/ConditionalSyntaxExtensions.cs index 51714eb..b1f9936 100644 --- a/src/N.SourceGenerators.UnionTypes/Extensions/ConditionalSyntaxExtensions.cs +++ b/src/N.SourceGenerators.UnionTypes/Extensions/ConditionalSyntaxExtensions.cs @@ -125,4 +125,14 @@ public static ParameterSyntax AddAttributeListsWhen( ? syntax.AddAttributeLists(items) : syntax; } + + public static SyntaxTriviaList AddWhen( + this SyntaxTriviaList syntax, + bool condition, + SyntaxTrivia trivia) + { + return condition + ? syntax.Add(trivia) + : syntax; + } } \ No newline at end of file diff --git a/src/N.SourceGenerators.UnionTypes/Helpers/RoslynUtils.cs b/src/N.SourceGenerators.UnionTypes/Helpers/RoslynUtils.cs index 82e636f..318f5f8 100644 --- a/src/N.SourceGenerators.UnionTypes/Helpers/RoslynUtils.cs +++ b/src/N.SourceGenerators.UnionTypes/Helpers/RoslynUtils.cs @@ -70,6 +70,14 @@ public static ThrowStatementSyntax ThrowInvalidOperationException(ExpressionSynt SyntaxFactory.Argument(expression) ); } + + public static ThrowStatementSyntax ThrowArgumentNullException(ExpressionSyntax expression) + { + return ThrowException( + "System.ArgumentNullException", + SyntaxFactory.Argument(expression) + ); + } public static ThrowStatementSyntax ThrowException(string type, params ArgumentSyntax[] arguments) { diff --git a/src/N.SourceGenerators.UnionTypes/Models/UnionType.cs b/src/N.SourceGenerators.UnionTypes/Models/UnionType.cs index f4cd1a8..150e0f9 100644 --- a/src/N.SourceGenerators.UnionTypes/Models/UnionType.cs +++ b/src/N.SourceGenerators.UnionTypes/Models/UnionType.cs @@ -150,4 +150,6 @@ public int GetHashCode(UnionType obj) { return obj.TypeFullName.GetHashCode(); } -} \ No newline at end of file +} + +internal record CompilationContext(bool SupportsNotNullWhenAttribute, bool SupportsThrowIfNull, bool NullableContextEnabled); \ No newline at end of file diff --git a/src/N.SourceGenerators.UnionTypes/N.SourceGenerators.UnionTypes.csproj b/src/N.SourceGenerators.UnionTypes/N.SourceGenerators.UnionTypes.csproj index 0b69cba..f2a0175 100644 --- a/src/N.SourceGenerators.UnionTypes/N.SourceGenerators.UnionTypes.csproj +++ b/src/N.SourceGenerators.UnionTypes/N.SourceGenerators.UnionTypes.csproj @@ -2,7 +2,7 @@ netstandard2.0 - 11 + 12 false @@ -10,7 +10,7 @@ true true ./nupkg - 0.26.0 + 0.27.0 true $(NoWarn);NU5128 diff --git a/src/N.SourceGenerators.UnionTypes/UnionTypesGenerator.Attributes.cs b/src/N.SourceGenerators.UnionTypes/UnionTypesGenerator.Attributes.cs index 2c1a925..d3350ef 100644 --- a/src/N.SourceGenerators.UnionTypes/UnionTypesGenerator.Attributes.cs +++ b/src/N.SourceGenerators.UnionTypes/UnionTypesGenerator.Attributes.cs @@ -15,7 +15,9 @@ public partial class UnionTypesGenerator private const string UnionTypeAttributeText = $$""" {{AutoGeneratedComment}} + #if NETCOREAPP3_1_OR_GREATER #nullable enable + #endif using System; using System.Runtime.CompilerServices; @@ -25,12 +27,24 @@ namespace N.SourceGenerators.UnionTypes internal sealed class UnionTypeAttribute : Attribute { public Type Type { get; } + #if NETCOREAPP3_1_OR_GREATER public string? Alias { get; } + #else + public string Alias { get; } + #endif public int Order { get; } public bool AllowNull { get; set; } + #if NETCOREAPP3_1_OR_GREATER public object? TypeDiscriminator { get; set; } - + #else + public object TypeDiscriminator { get; set; } + #endif + + #if NETCOREAPP3_1_OR_GREATER public UnionTypeAttribute(Type type, string? alias = null, [CallerLineNumber] int order = 0) + #else + public UnionTypeAttribute(Type type, string alias = null, [CallerLineNumber] int order = 0) + #endif { Type = type; Alias = alias; @@ -42,7 +56,9 @@ public UnionTypeAttribute(Type type, string? alias = null, [CallerLineNumber] in private const string GenericUnionTypeAttributeText = $$""" {{AutoGeneratedComment}} + #if NETCOREAPP3_1_OR_GREATER #nullable enable + #endif using System; using System.Runtime.CompilerServices; @@ -51,16 +67,24 @@ namespace N.SourceGenerators.UnionTypes [AttributeUsage(AttributeTargets.GenericParameter, Inherited = false, AllowMultiple = false)] internal sealed class GenericUnionTypeAttribute : Attribute { + #if NETCOREAPP3_1_OR_GREATER public string? Alias { get; set; } public bool AllowNull { get; set; } public object? TypeDiscriminator { get; set; } + #else + public string Alias { get; set; } + public bool AllowNull { get; set; } + public object TypeDiscriminator { get; set; } + #endif } } """; private const string JsonPolymorphicUnionAttributeText = $$""" {{AutoGeneratedComment}} + #if NETCOREAPP3_1_OR_GREATER #nullable enable + #endif using System; using System.Runtime.CompilerServices; @@ -69,14 +93,20 @@ namespace N.SourceGenerators.UnionTypes [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] internal sealed class JsonPolymorphicUnionAttribute : Attribute { + #if NETCOREAPP3_1_OR_GREATER public string? TypeDiscriminatorPropertyName { get; set; } + #else + public string TypeDiscriminatorPropertyName { get; set; } + #endif } } """; private const string UnionConverterFromAttributeText = $$""" {{AutoGeneratedComment}} + #if NETCOREAPP3_1_OR_GREATER #nullable enable + #endif using System; using System.Runtime.CompilerServices; @@ -97,7 +127,9 @@ public UnionConverterFromAttribute(Type fromType) private const string UnionConverterToAttributeText = $$""" {{AutoGeneratedComment}} + #if NETCOREAPP3_1_OR_GREATER #nullable enable + #endif using System; using System.Runtime.CompilerServices; @@ -117,7 +149,9 @@ public UnionConverterToAttribute(Type toType) """; private const string UnionConverterAttributeText = """ + #if NETCOREAPP3_1_OR_GREATER #nullable enable + #endif using System; using System.Runtime.CompilerServices; @@ -128,9 +162,17 @@ sealed class UnionConverterAttribute : Attribute { public Type FromType { get; } public Type ToType { get; } + #if NETCOREAPP3_1_OR_GREATER public string? MethodName { get; } + #else + public string MethodName { get; } + #endif + #if NETCOREAPP3_1_OR_GREATER public UnionConverterAttribute(Type fromType, Type toType, string? methodName = null) + #else + public UnionConverterAttribute(Type fromType, Type toType, string methodName = null) + #endif { FromType = fromType; ToType = toType; diff --git a/src/N.SourceGenerators.UnionTypes/UnionTypesGenerator.Converters.cs b/src/N.SourceGenerators.UnionTypes/UnionTypesGenerator.Converters.cs index 2e0d6e9..6d38a5c 100644 --- a/src/N.SourceGenerators.UnionTypes/UnionTypesGenerator.Converters.cs +++ b/src/N.SourceGenerators.UnionTypes/UnionTypesGenerator.Converters.cs @@ -8,47 +8,52 @@ namespace N.SourceGenerators.UnionTypes; public sealed partial class UnionTypesGenerator { - private static void GenerateConverters(IncrementalGeneratorInitializationContext context) + private static void GenerateConverters(IncrementalGeneratorInitializationContext context, + IncrementalValueProvider compilationContextProvider) { var toConverters = GetUnionConverters( context, UnionConverterToAttributeName, (containerType, otherTypes) => new UnionToConverter(containerType, otherTypes)); - ProcessConverters(context, toConverters); + ProcessConverters(context, toConverters, compilationContextProvider); var fromConverters = GetUnionConverters( context, UnionConverterFromAttributeName, (containerType, otherTypes) => new UnionFromConverter(containerType, otherTypes)); - ProcessConverters(context, fromConverters); + ProcessConverters(context, fromConverters, compilationContextProvider); var unionConverters = GetUnionConverters(context); - ProcessConverters(context, unionConverters); + ProcessConverters(context, unionConverters, compilationContextProvider); } private static void ProcessConverters( IncrementalGeneratorInitializationContext context, - IncrementalValuesProvider unionConverters) + IncrementalValuesProvider unionConverters, + IncrementalValueProvider compilationContextProvider) { + var combination = unionConverters.Combine(compilationContextProvider); + context.RegisterImplementationSourceOutput( - unionConverters, + combination, (ctx, item) => { - TypeDeclarationSyntax typeDeclaration = ClassDeclaration(item.Name); + UnionConverter unionConverter = item.Left; + TypeDeclarationSyntax typeDeclaration = ClassDeclaration(unionConverter.Name); typeDeclaration = typeDeclaration .AddModifiersWhen( - item.IsStatic, + unionConverter.IsStatic, Token(SyntaxKind.StaticKeyword) ).AddModifiers(Token(SyntaxKind.PartialKeyword)); bool saveSource = false; - foreach (var converter in item.Converters) + foreach (var converter in unionConverter.Converters) { UnionType fromType = converter.FromType; UnionType toType = converter.ToType; - bool canConvert = CanConvert(fromType, toType, item.Location, out var diagnostic); + bool canConvert = CanConvert(fromType, toType, unionConverter.Location, out var diagnostic); if (canConvert) { @@ -60,7 +65,7 @@ private static void ProcessConverters( Token(SyntaxKind.StaticKeyword) ).AddParameterListParameters( Parameter(fromType.TypeFullName, "value") - .AddModifiersWhen(item.IsStatic, Token(SyntaxKind.ThisKeyword)) + .AddModifiersWhen(unionConverter.IsStatic, Token(SyntaxKind.ThisKeyword)) ).AddBodyStatements( ReturnMatchConversion(fromType, toType) ); @@ -76,8 +81,8 @@ private static void ProcessConverters( if (saveSource) { - CompilationUnitSyntax compilationUnit = GetCompilationUnit(typeDeclaration, item.Namespace); - ctx.AddSource($"{item.Name}Converters.g.cs", compilationUnit.GetText(Encoding.UTF8)); + CompilationUnitSyntax compilationUnit = GetCompilationUnit(typeDeclaration, unionConverter.Namespace, item.Right); + ctx.AddSource($"{unionConverter.Name}Converters.g.cs", compilationUnit.GetText(Encoding.UTF8)); } }); } @@ -167,14 +172,18 @@ private static IncrementalValuesProvider GetUnionConverters( } private static void ProcessConverters(IncrementalGeneratorInitializationContext context, - IncrementalValuesProvider fromConverters) + IncrementalValuesProvider fromConverters, + IncrementalValueProvider compilationContextProvider) where T : IUnionConverter { + var combination = fromConverters.Combine(compilationContextProvider); + context.RegisterImplementationSourceOutput( - fromConverters, + combination, (ctx, item) => { - UnionType containerType = item.ContainerType; + T unionConverter = item.Left; + UnionType containerType = unionConverter.ContainerType; TypeDeclarationSyntax typeDeclaration = containerType.IsReferenceType ? ClassDeclaration(containerType.Name) : StructDeclaration(containerType.Name); @@ -183,7 +192,7 @@ private static void ProcessConverters(IncrementalGeneratorInitializationConte .AddModifiers(Token(SyntaxKind.PartialKeyword)); bool saveSource = false; - foreach ((UnionType fromType, UnionType toType) in item) + foreach ((UnionType fromType, UnionType toType) in unionConverter) { bool canConvert = CanConvert(fromType, toType, containerType.Location, out var diagnostic); @@ -201,8 +210,8 @@ private static void ProcessConverters(IncrementalGeneratorInitializationConte if (saveSource) { CompilationUnitSyntax compilationUnit = - GetCompilationUnit(typeDeclaration, containerType.Namespace); - ctx.AddSource(item.SourceHintName, compilationUnit.GetText(Encoding.UTF8)); + GetCompilationUnit(typeDeclaration, containerType.Namespace, item.Right); + ctx.AddSource(unionConverter.SourceHintName, compilationUnit.GetText(Encoding.UTF8)); } }); } diff --git a/src/N.SourceGenerators.UnionTypes/UnionTypesGenerator.EqualityMembers.cs b/src/N.SourceGenerators.UnionTypes/UnionTypesGenerator.EqualityMembers.cs index 6b65a03..7d84329 100644 --- a/src/N.SourceGenerators.UnionTypes/UnionTypesGenerator.EqualityMembers.cs +++ b/src/N.SourceGenerators.UnionTypes/UnionTypesGenerator.EqualityMembers.cs @@ -30,10 +30,10 @@ static StatementSyntax AliasStatement(UnionTypeVariant variant) } } - private static OperatorDeclarationSyntax EqualsOperator(UnionType unionType, bool equal) + private static OperatorDeclarationSyntax EqualsOperator(UnionType unionType, bool equal, CompilationContext compilationContext) { TypeSyntax parameterType = IdentifierName(unionType.Name) - .NullableTypeWhen(unionType.IsReferenceType); + .NullableTypeWhen(unionType.IsReferenceType && compilationContext.NullableContextEnabled); ExpressionSyntax equalExpression = unionType.IsReferenceType ? InvocationExpression( @@ -67,7 +67,7 @@ private static OperatorDeclarationSyntax EqualsOperator(UnionType unionType, boo ); } - private static MemberDeclarationSyntax GenericEqualsMethod(UnionType unionType) + private static MemberDeclarationSyntax GenericEqualsMethod(UnionType unionType, CompilationContext compilationContext) { bool isReferenceType = unionType.IsReferenceType; @@ -80,7 +80,7 @@ private static MemberDeclarationSyntax GenericEqualsMethod(UnionType unionType) Parameter(Identifier("other")) .WithType( IdentifierName(unionType.Name) - .NullableTypeWhen(isReferenceType) + .NullableTypeWhen(isReferenceType && compilationContext.NullableContextEnabled) ) ).AddBodyStatements( BodyStatements().ToArray() @@ -129,7 +129,7 @@ IEnumerable BodyStatements() } } - private static MemberDeclarationSyntax ClassEqualsMethod(UnionType unionType) + private static MemberDeclarationSyntax ClassEqualsMethod(UnionType unionType, CompilationContext compilationContext) { return MethodDeclaration( IdentifierName("bool"), @@ -138,7 +138,7 @@ private static MemberDeclarationSyntax ClassEqualsMethod(UnionType unionType) Token(SyntaxKind.PublicKeyword), Token(SyntaxKind.OverrideKeyword) ).AddParameterListParameters( - Parameter(NullableType(ObjectType()), "other") + Parameter(ObjectType().NullableTypeWhen(compilationContext.NullableContextEnabled), "other") ).AddBodyStatements( BodyStatements().ToArray() ); diff --git a/src/N.SourceGenerators.UnionTypes/UnionTypesGenerator.Json.cs b/src/N.SourceGenerators.UnionTypes/UnionTypesGenerator.Json.cs index 1b460b0..3136185 100644 --- a/src/N.SourceGenerators.UnionTypes/UnionTypesGenerator.Json.cs +++ b/src/N.SourceGenerators.UnionTypes/UnionTypesGenerator.Json.cs @@ -8,15 +8,16 @@ namespace N.SourceGenerators.UnionTypes; public sealed partial class UnionTypesGenerator { private static void GenerateJsonConverter(UnionType unionType, - SourceProductionContext context) + SourceProductionContext context, + CompilationContext compilationContext) { context.CancellationToken.ThrowIfCancellationRequested(); - BuildJsonConverter(unionType, context); + BuildJsonConverter(unionType, context, compilationContext); context.CancellationToken.ThrowIfCancellationRequested(); - BuildJsonConverterAttribute(unionType, context); + BuildJsonConverterAttribute(unionType, context, compilationContext); } - private static void BuildJsonConverter(UnionType unionType, SourceProductionContext context) + private static void BuildJsonConverter(UnionType unionType, SourceProductionContext context, CompilationContext compilationContext) { TypeDeclarationSyntax converterDeclaration = ClassDeclaration(unionType.Name + "JsonConverter") .AddModifiers(Token(SyntaxKind.InternalKeyword)) @@ -33,11 +34,11 @@ private static void BuildJsonConverter(UnionType unionType, SourceProductionCont WriteJsonConverterMethod(unionType) ); - CompilationUnitSyntax compilationUnit = GetCompilationUnit(converterDeclaration, unionType.Namespace); + CompilationUnitSyntax compilationUnit = GetCompilationUnit(converterDeclaration, unionType.Namespace, compilationContext); context.AddSource($"{unionType.SourceCodeFileName}JsonConverter.g.cs", compilationUnit.GetText(Encoding.UTF8)); } - private static void BuildJsonConverterAttribute(UnionType unionType, SourceProductionContext context) + private static void BuildJsonConverterAttribute(UnionType unionType, SourceProductionContext context, CompilationContext compilationContext) { TypeDeclarationSyntax converterDeclaration = ClassDeclaration(unionType.Name + "JsonConverterAttribute") .AddModifiers( @@ -66,7 +67,7 @@ private static void BuildJsonConverterAttribute(UnionType unionType, SourceProdu ) ); - CompilationUnitSyntax compilationUnit = GetCompilationUnit(converterDeclaration, unionType.Namespace); + CompilationUnitSyntax compilationUnit = GetCompilationUnit(converterDeclaration, unionType.Namespace, compilationContext); context.AddSource($"{unionType.SourceCodeFileName}JsonConverterAttribute.g.cs", compilationUnit.GetText(Encoding.UTF8)); } diff --git a/src/N.SourceGenerators.UnionTypes/UnionTypesGenerator.cs b/src/N.SourceGenerators.UnionTypes/UnionTypesGenerator.cs index 910da8a..310f9cb 100644 --- a/src/N.SourceGenerators.UnionTypes/UnionTypesGenerator.cs +++ b/src/N.SourceGenerators.UnionTypes/UnionTypesGenerator.cs @@ -22,6 +22,18 @@ public sealed partial class UnionTypesGenerator : IIncrementalGenerator public void Initialize(IncrementalGeneratorInitializationContext context) { AddAttributesSource(context); + + var compilationContextProvider = context.CompilationProvider.Select((compilation, ct) => + { + ct.ThrowIfCancellationRequested(); + // compilation.ReferencedAssemblyNames + // compilation.GetSemanticModel().GetNullableContext() == NullableContext.Enabled + var supportsNotNullWhenAttribute = compilation.GetTypeByMetadataName("System.Diagnostics.CodeAnalysis.NotNullWhenAttribute") != null; + var supportsThrowIfNull = compilation.GetTypeByMetadataName("System.ArgumentNullException")?.GetMembers("ThrowIfNull").Any() ?? false; + var nullableContextEnabled = compilation.HasLanguageVersionAtLeastEqualTo(LanguageVersion.CSharp8); + CompilationContext compilationContext = new(supportsNotNullWhenAttribute, supportsThrowIfNull, nullableContextEnabled); + return compilationContext; + }); var unionTypes = GetUnionTypes(context); var genericUnionTypes = GetGenericUnionTypes(context); @@ -32,18 +44,20 @@ public void Initialize(IncrementalGeneratorInitializationContext context) .SelectMany(ProcessCollections); var unionTypeDiagnostics = GetUnionTypeDiagnostics(uniqueUnionTypes); - ProcessValues(context, unionTypeDiagnostics, GenerateUnionType); + ProcessValues(context, compilationContextProvider, unionTypeDiagnostics, GenerateUnionType); var jsonTypes = unionTypeDiagnostics .Where(vd => vd.Diagnostics.Count == 0) .Where(vd => vd.Value.GenerateJsonConverter); + var jsonTypesCombination = jsonTypes.Combine(compilationContextProvider); + // TODO test System.Text.Json is available, add diagnostics context.RegisterImplementationSourceOutput( - jsonTypes, - (ctx, item) => { GenerateJsonConverter(item.Value, ctx); }); + jsonTypesCombination, + (ctx, item) => { GenerateJsonConverter(item.Left.Value, ctx, item.Right); }); - GenerateConverters(context); + GenerateConverters(context, compilationContextProvider); } private IEnumerable ProcessCollections( @@ -220,6 +234,7 @@ bool GetAllowNullValue(AttributeData attribute) } static void GenerateUnionType(UnionType unionType, + CompilationContext compilationContext, SourceProductionContext context) { context.CancellationToken.ThrowIfCancellationRequested(); @@ -232,7 +247,7 @@ static void GenerateUnionType(UnionType unionType, .AddAttributeLists(GetTypeAttributes(unionType)) .AddModifiers(Token(SyntaxKind.PartialKeyword)) .AddMembers(VariantIdField(unionType.UseStructLayout)) - .AddMembers(VariantsMembers(unionType)) + .AddMembers(VariantsMembers(unionType, compilationContext)) .AddMembers( MatchMethod(unionType, isAsync: false), MatchMethod(unionType, isAsync: true), @@ -241,12 +256,12 @@ static void GenerateUnionType(UnionType unionType, ValueTypeProperty(unionType), ValueAliasProperty(unionType), GetHashCodeMethod(unionType), - EqualsOperator(unionType, equal: true), - EqualsOperator(unionType, equal: false), - GenericEqualsMethod(unionType) + EqualsOperator(unionType, equal: true, compilationContext), + EqualsOperator(unionType, equal: false, compilationContext), + GenericEqualsMethod(unionType, compilationContext) ) .AddMembersWhen(!unionType.HasToStringMethod, ToStringMethod(unionType)) - .AddMembersWhen(unionType.IsReferenceType, ClassEqualsMethod(unionType)) + .AddMembersWhen(unionType.IsReferenceType, ClassEqualsMethod(unionType, compilationContext)) .AddMembersWhen(!unionType.IsReferenceType, StructEqualsMethod(unionType)) .WithBaseList( BaseList( @@ -261,14 +276,14 @@ static void GenerateUnionType(UnionType unionType, ) ); - CompilationUnitSyntax compilationUnit = GetCompilationUnit(typeDeclaration, unionType.Namespace); + CompilationUnitSyntax compilationUnit = GetCompilationUnit(typeDeclaration, unionType.Namespace, compilationContext); context.AddSource($"{unionType.SourceCodeFileName}.g.cs", compilationUnit.GetText(Encoding.UTF8)); } private static CompilationUnitSyntax GetCompilationUnit(TypeDeclarationSyntax typeDeclaration, - string? typeNamespace) + string? typeNamespace, CompilationContext compilationContext) { - SyntaxTriviaList syntaxTriviaList = GetTriviaList(); + SyntaxTriviaList syntaxTriviaList = GetTriviaList(compilationContext); CompilationUnitSyntax compilationUnit; if (typeNamespace is null) @@ -291,27 +306,37 @@ private static CompilationUnitSyntax GetCompilationUnit(TypeDeclarationSyntax ty return compilationUnit; } - private static SyntaxTriviaList GetTriviaList() + private static SyntaxTriviaList GetTriviaList(CompilationContext compilationContext) { return TriviaList( Comment(AutoGeneratedComment), - Trivia(PragmaWarningDirectiveTrivia(Token(SyntaxKind.DisableKeyword), true)), - Trivia(NullableDirectiveTrivia(Token(SyntaxKind.EnableKeyword), true))); + Trivia(PragmaWarningDirectiveTrivia(Token(SyntaxKind.DisableKeyword), true))) + .AddWhen( + compilationContext.NullableContextEnabled, + Trivia(NullableDirectiveTrivia(Token(SyntaxKind.EnableKeyword), true))); } - private static void ProcessValues( - IncrementalGeneratorInitializationContext context, + private static void ProcessValues(IncrementalGeneratorInitializationContext context, + IncrementalValueProvider compilationContextProvider, IncrementalValuesProvider> valueDiagnostics, - Action processAction) + Action processAction) { ReportDiagnostics(context, valueDiagnostics); var validValues = valueDiagnostics .Where(vd => vd.Diagnostics.Count == 0); + var combination = validValues.Combine(compilationContextProvider); + context.RegisterImplementationSourceOutput( - validValues, - (ctx, item) => { processAction(item.Value, ctx); }); + combination, + (ctx, item) => + { + ValueDiagnostics diagnostics = item.Left; + CompilationContext compilationContext = item.Item2; + + processAction(diagnostics.Value, compilationContext, ctx); + }); } private static MemberDeclarationSyntax VariantIdField(bool useStructLayout) @@ -369,11 +394,11 @@ private static AttributeListSyntax[] GetTypeAttributes(UnionType unionType) return result.ToArray(); } - private static MemberDeclarationSyntax[] VariantsMembers(UnionType unionType) + private static MemberDeclarationSyntax[] VariantsMembers(UnionType unionType, CompilationContext compilationContext) { var variantsMembers = unionType .Variants - .SelectMany(v => VariantMembers(unionType, v)) + .SelectMany(v => VariantMembers(unionType, v, compilationContext)) .ToArray(); return variantsMembers; @@ -381,20 +406,21 @@ private static MemberDeclarationSyntax[] VariantsMembers(UnionType unionType) private static IEnumerable VariantMembers( UnionType unionType, - UnionTypeVariant variant) + UnionTypeVariant variant, + CompilationContext compilationContext) { yield return VariantConstant(variant); yield return Field(unionType, variant); yield return IsProperty(variant); yield return AsPropertyWithStructLayout(variant); - yield return Ctor(unionType, variant); + yield return Ctor(unionType, variant, compilationContext); if (!variant.IsInterface) { yield return ImplicitOperatorToUnion(unionType, variant); yield return ExplicitOperatorFromUnion(unionType, variant); } - yield return TryGetMethod(variant); + yield return TryGetMethod(variant, compilationContext); } /// @@ -479,8 +505,8 @@ private static StatementSyntax[] AsPropertyWithStructLayoutBody(UnionTypeVariant { ExpressionSyntax returnSyntax = NotNullableArgumentExpression(variant, memberName); - return new StatementSyntax[] - { + return + [ IfStatement( IsPropertyCondition(variant, memberName), ReturnStatement(returnSyntax) @@ -495,10 +521,10 @@ private static StatementSyntax[] AsPropertyWithStructLayoutBody(UnionTypeVariant InterpolatedText($" not {variant.Alias}.") ) ) - }; + ]; } - private static MemberDeclarationSyntax Ctor(UnionType unionType, UnionTypeVariant variant) + private static MemberDeclarationSyntax Ctor(UnionType unionType, UnionTypeVariant variant, CompilationContext compilationContext) { InvocationExpressionSyntax checkArgumentExpression = InvocationExpression( MemberAccess("System.ArgumentNullException", "ThrowIfNull") @@ -507,6 +533,14 @@ private static MemberDeclarationSyntax Ctor(UnionType unionType, UnionTypeVarian Argument(variant.ParameterName) ); + var checkArgumentLegacy = IfStatement( + BinaryExpression( + SyntaxKind.EqualsExpression, + IdentifierName(variant.ParameterName), + LiteralExpression(SyntaxKind.NullLiteralExpression)), + ThrowArgumentNullException(NameOfExpressions(variant.ParameterName)) + ); + AssignmentExpressionSyntax assignmentExpression = SimpleAssignmentExpression( variant.FieldName, variant.ParameterName); @@ -516,8 +550,10 @@ private static MemberDeclarationSyntax Ctor(UnionType unionType, UnionTypeVarian .AddParameterListParameters( Parameter(variant.TypeFullName, variant.ParameterName) ) - .AddBodyStatementsWhen(!unionType.UseStructLayout && !variant.AllowNull, + .AddBodyStatementsWhen(!unionType.UseStructLayout && !variant.AllowNull && compilationContext.SupportsThrowIfNull, ExpressionStatement(checkArgumentExpression)) + .AddBodyStatementsWhen(!unionType.UseStructLayout && !variant.AllowNull && !compilationContext.SupportsThrowIfNull, + checkArgumentLegacy) .AddBodyStatements( ExpressionStatement(SimpleAssignmentExpression( VariantIdFieldName, @@ -569,10 +605,10 @@ private static MemberDeclarationSyntax ExplicitOperatorFromUnion(UnionType union .AddBodyStatements(AsPropertyWithStructLayoutBody(variant, "value")); } - private static MemberDeclarationSyntax TryGetMethod(UnionTypeVariant variant) + private static MemberDeclarationSyntax TryGetMethod(UnionTypeVariant variant, CompilationContext compilationContext) { AttributeListSyntax attributeList = AttributeList(); - if (!variant.AllowNull) + if (!variant.AllowNull && compilationContext.SupportsNotNullWhenAttribute) { attributeList = attributeList.AddAttributes( Attribute(IdentifierName("System.Diagnostics.CodeAnalysis.NotNullWhen"), @@ -788,7 +824,7 @@ private static MemberDeclarationSyntax ValueAliasProperty(UnionType unionType) ) ) ); - + static StatementSyntax AliasStatement(UnionTypeVariant variant) { return IfStatement( diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ExternalConverter#GenericUnionTypeAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ExternalConverter#GenericUnionTypeAttribute.g.verified.cs index 9930562..17a28f9 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ExternalConverter#GenericUnionTypeAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ExternalConverter#GenericUnionTypeAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -12,8 +14,14 @@ namespace N.SourceGenerators.UnionTypes [AttributeUsage(AttributeTargets.GenericParameter, Inherited = false, AllowMultiple = false)] internal sealed class GenericUnionTypeAttribute : Attribute { +#if NETCOREAPP3_1_OR_GREATER public string? Alias { get; set; } public bool AllowNull { get; set; } public object? TypeDiscriminator { get; set; } +#else + public string Alias { get; set; } + public bool AllowNull { get; set; } + public object TypeDiscriminator { get; set; } +#endif } } \ No newline at end of file diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ExternalConverter#JsonPolymorphicUnionAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ExternalConverter#JsonPolymorphicUnionAttribute.g.verified.cs index e6b2d7c..ee781ad 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ExternalConverter#JsonPolymorphicUnionAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ExternalConverter#JsonPolymorphicUnionAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -12,6 +14,10 @@ namespace N.SourceGenerators.UnionTypes [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] internal sealed class JsonPolymorphicUnionAttribute : Attribute { +#if NETCOREAPP3_1_OR_GREATER public string? TypeDiscriminatorPropertyName { get; set; } +#else + public string TypeDiscriminatorPropertyName { get; set; } +#endif } } \ No newline at end of file diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ExternalConverter#UnionConverterAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ExternalConverter#UnionConverterAttribute.g.verified.cs index 3e6fd2b..973b6e2 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ExternalConverter#UnionConverterAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ExternalConverter#UnionConverterAttribute.g.verified.cs @@ -1,5 +1,7 @@ //HintName: UnionConverterAttribute.g.cs +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -10,9 +12,17 @@ sealed class UnionConverterAttribute : Attribute { public Type FromType { get; } public Type ToType { get; } +#if NETCOREAPP3_1_OR_GREATER public string? MethodName { get; } +#else + public string MethodName { get; } +#endif +#if NETCOREAPP3_1_OR_GREATER public UnionConverterAttribute(Type fromType, Type toType, string? methodName = null) +#else + public UnionConverterAttribute(Type fromType, Type toType, string methodName = null) +#endif { FromType = fromType; ToType = toType; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ExternalConverter#UnionConverterFromAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ExternalConverter#UnionConverterFromAttribute.g.verified.cs index d740ef3..222e936 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ExternalConverter#UnionConverterFromAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ExternalConverter#UnionConverterFromAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ExternalConverter#UnionConverterToAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ExternalConverter#UnionConverterToAttribute.g.verified.cs index fae1e4d..28901ff 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ExternalConverter#UnionConverterToAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ExternalConverter#UnionConverterToAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ExternalConverter#UnionTypeAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ExternalConverter#UnionTypeAttribute.g.verified.cs index 335ae09..927bc14 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ExternalConverter#UnionTypeAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ExternalConverter#UnionTypeAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -13,12 +15,24 @@ namespace N.SourceGenerators.UnionTypes internal sealed class UnionTypeAttribute : Attribute { public Type Type { get; } +#if NETCOREAPP3_1_OR_GREATER public string? Alias { get; } +#else + public string Alias { get; } +#endif public int Order { get; } public bool AllowNull { get; set; } +#if NETCOREAPP3_1_OR_GREATER public object? TypeDiscriminator { get; set; } +#else + public object TypeDiscriminator { get; set; } +#endif +#if NETCOREAPP3_1_OR_GREATER public UnionTypeAttribute(Type type, string? alias = null, [CallerLineNumber] int order = 0) +#else + public UnionTypeAttribute(Type type, string alias = null, [CallerLineNumber] int order = 0) +#endif { Type = type; Alias = alias; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ExternalConverterReportsDiagnostic#GenericUnionTypeAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ExternalConverterReportsDiagnostic#GenericUnionTypeAttribute.g.verified.cs index 9930562..17a28f9 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ExternalConverterReportsDiagnostic#GenericUnionTypeAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ExternalConverterReportsDiagnostic#GenericUnionTypeAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -12,8 +14,14 @@ namespace N.SourceGenerators.UnionTypes [AttributeUsage(AttributeTargets.GenericParameter, Inherited = false, AllowMultiple = false)] internal sealed class GenericUnionTypeAttribute : Attribute { +#if NETCOREAPP3_1_OR_GREATER public string? Alias { get; set; } public bool AllowNull { get; set; } public object? TypeDiscriminator { get; set; } +#else + public string Alias { get; set; } + public bool AllowNull { get; set; } + public object TypeDiscriminator { get; set; } +#endif } } \ No newline at end of file diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ExternalConverterReportsDiagnostic#JsonPolymorphicUnionAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ExternalConverterReportsDiagnostic#JsonPolymorphicUnionAttribute.g.verified.cs index e6b2d7c..ee781ad 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ExternalConverterReportsDiagnostic#JsonPolymorphicUnionAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ExternalConverterReportsDiagnostic#JsonPolymorphicUnionAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -12,6 +14,10 @@ namespace N.SourceGenerators.UnionTypes [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] internal sealed class JsonPolymorphicUnionAttribute : Attribute { +#if NETCOREAPP3_1_OR_GREATER public string? TypeDiscriminatorPropertyName { get; set; } +#else + public string TypeDiscriminatorPropertyName { get; set; } +#endif } } \ No newline at end of file diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ExternalConverterReportsDiagnostic#UnionConverterAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ExternalConverterReportsDiagnostic#UnionConverterAttribute.g.verified.cs index 3e6fd2b..973b6e2 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ExternalConverterReportsDiagnostic#UnionConverterAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ExternalConverterReportsDiagnostic#UnionConverterAttribute.g.verified.cs @@ -1,5 +1,7 @@ //HintName: UnionConverterAttribute.g.cs +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -10,9 +12,17 @@ sealed class UnionConverterAttribute : Attribute { public Type FromType { get; } public Type ToType { get; } +#if NETCOREAPP3_1_OR_GREATER public string? MethodName { get; } +#else + public string MethodName { get; } +#endif +#if NETCOREAPP3_1_OR_GREATER public UnionConverterAttribute(Type fromType, Type toType, string? methodName = null) +#else + public UnionConverterAttribute(Type fromType, Type toType, string methodName = null) +#endif { FromType = fromType; ToType = toType; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ExternalConverterReportsDiagnostic#UnionConverterFromAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ExternalConverterReportsDiagnostic#UnionConverterFromAttribute.g.verified.cs index d740ef3..222e936 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ExternalConverterReportsDiagnostic#UnionConverterFromAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ExternalConverterReportsDiagnostic#UnionConverterFromAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ExternalConverterReportsDiagnostic#UnionConverterToAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ExternalConverterReportsDiagnostic#UnionConverterToAttribute.g.verified.cs index fae1e4d..28901ff 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ExternalConverterReportsDiagnostic#UnionConverterToAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ExternalConverterReportsDiagnostic#UnionConverterToAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ExternalConverterReportsDiagnostic#UnionTypeAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ExternalConverterReportsDiagnostic#UnionTypeAttribute.g.verified.cs index 335ae09..927bc14 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ExternalConverterReportsDiagnostic#UnionTypeAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ExternalConverterReportsDiagnostic#UnionTypeAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -13,12 +15,24 @@ namespace N.SourceGenerators.UnionTypes internal sealed class UnionTypeAttribute : Attribute { public Type Type { get; } +#if NETCOREAPP3_1_OR_GREATER public string? Alias { get; } +#else + public string Alias { get; } +#endif public int Order { get; } public bool AllowNull { get; set; } +#if NETCOREAPP3_1_OR_GREATER public object? TypeDiscriminator { get; set; } +#else + public object TypeDiscriminator { get; set; } +#endif +#if NETCOREAPP3_1_OR_GREATER public UnionTypeAttribute(Type type, string? alias = null, [CallerLineNumber] int order = 0) +#else + public UnionTypeAttribute(Type type, string alias = null, [CallerLineNumber] int order = 0) +#endif { Type = type; Alias = alias; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.FromConverter#GenericUnionTypeAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.FromConverter#GenericUnionTypeAttribute.g.verified.cs index 9930562..17a28f9 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.FromConverter#GenericUnionTypeAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.FromConverter#GenericUnionTypeAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -12,8 +14,14 @@ namespace N.SourceGenerators.UnionTypes [AttributeUsage(AttributeTargets.GenericParameter, Inherited = false, AllowMultiple = false)] internal sealed class GenericUnionTypeAttribute : Attribute { +#if NETCOREAPP3_1_OR_GREATER public string? Alias { get; set; } public bool AllowNull { get; set; } public object? TypeDiscriminator { get; set; } +#else + public string Alias { get; set; } + public bool AllowNull { get; set; } + public object TypeDiscriminator { get; set; } +#endif } } \ No newline at end of file diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.FromConverter#JsonPolymorphicUnionAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.FromConverter#JsonPolymorphicUnionAttribute.g.verified.cs index e6b2d7c..ee781ad 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.FromConverter#JsonPolymorphicUnionAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.FromConverter#JsonPolymorphicUnionAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -12,6 +14,10 @@ namespace N.SourceGenerators.UnionTypes [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] internal sealed class JsonPolymorphicUnionAttribute : Attribute { +#if NETCOREAPP3_1_OR_GREATER public string? TypeDiscriminatorPropertyName { get; set; } +#else + public string TypeDiscriminatorPropertyName { get; set; } +#endif } } \ No newline at end of file diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.FromConverter#UnionConverterAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.FromConverter#UnionConverterAttribute.g.verified.cs index 3e6fd2b..973b6e2 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.FromConverter#UnionConverterAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.FromConverter#UnionConverterAttribute.g.verified.cs @@ -1,5 +1,7 @@ //HintName: UnionConverterAttribute.g.cs +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -10,9 +12,17 @@ sealed class UnionConverterAttribute : Attribute { public Type FromType { get; } public Type ToType { get; } +#if NETCOREAPP3_1_OR_GREATER public string? MethodName { get; } +#else + public string MethodName { get; } +#endif +#if NETCOREAPP3_1_OR_GREATER public UnionConverterAttribute(Type fromType, Type toType, string? methodName = null) +#else + public UnionConverterAttribute(Type fromType, Type toType, string methodName = null) +#endif { FromType = fromType; ToType = toType; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.FromConverter#UnionConverterFromAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.FromConverter#UnionConverterFromAttribute.g.verified.cs index d740ef3..222e936 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.FromConverter#UnionConverterFromAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.FromConverter#UnionConverterFromAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.FromConverter#UnionConverterToAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.FromConverter#UnionConverterToAttribute.g.verified.cs index fae1e4d..28901ff 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.FromConverter#UnionConverterToAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.FromConverter#UnionConverterToAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.FromConverter#UnionTypeAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.FromConverter#UnionTypeAttribute.g.verified.cs index 335ae09..927bc14 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.FromConverter#UnionTypeAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.FromConverter#UnionTypeAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -13,12 +15,24 @@ namespace N.SourceGenerators.UnionTypes internal sealed class UnionTypeAttribute : Attribute { public Type Type { get; } +#if NETCOREAPP3_1_OR_GREATER public string? Alias { get; } +#else + public string Alias { get; } +#endif public int Order { get; } public bool AllowNull { get; set; } +#if NETCOREAPP3_1_OR_GREATER public object? TypeDiscriminator { get; set; } +#else + public object TypeDiscriminator { get; set; } +#endif +#if NETCOREAPP3_1_OR_GREATER public UnionTypeAttribute(Type type, string? alias = null, [CallerLineNumber] int order = 0) +#else + public UnionTypeAttribute(Type type, string alias = null, [CallerLineNumber] int order = 0) +#endif { Type = type; Alias = alias; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.FromConverterReportsDiagnostic#GenericUnionTypeAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.FromConverterReportsDiagnostic#GenericUnionTypeAttribute.g.verified.cs index 9930562..17a28f9 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.FromConverterReportsDiagnostic#GenericUnionTypeAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.FromConverterReportsDiagnostic#GenericUnionTypeAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -12,8 +14,14 @@ namespace N.SourceGenerators.UnionTypes [AttributeUsage(AttributeTargets.GenericParameter, Inherited = false, AllowMultiple = false)] internal sealed class GenericUnionTypeAttribute : Attribute { +#if NETCOREAPP3_1_OR_GREATER public string? Alias { get; set; } public bool AllowNull { get; set; } public object? TypeDiscriminator { get; set; } +#else + public string Alias { get; set; } + public bool AllowNull { get; set; } + public object TypeDiscriminator { get; set; } +#endif } } \ No newline at end of file diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.FromConverterReportsDiagnostic#JsonPolymorphicUnionAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.FromConverterReportsDiagnostic#JsonPolymorphicUnionAttribute.g.verified.cs index e6b2d7c..ee781ad 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.FromConverterReportsDiagnostic#JsonPolymorphicUnionAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.FromConverterReportsDiagnostic#JsonPolymorphicUnionAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -12,6 +14,10 @@ namespace N.SourceGenerators.UnionTypes [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] internal sealed class JsonPolymorphicUnionAttribute : Attribute { +#if NETCOREAPP3_1_OR_GREATER public string? TypeDiscriminatorPropertyName { get; set; } +#else + public string TypeDiscriminatorPropertyName { get; set; } +#endif } } \ No newline at end of file diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.FromConverterReportsDiagnostic#UnionConverterAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.FromConverterReportsDiagnostic#UnionConverterAttribute.g.verified.cs index 3e6fd2b..973b6e2 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.FromConverterReportsDiagnostic#UnionConverterAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.FromConverterReportsDiagnostic#UnionConverterAttribute.g.verified.cs @@ -1,5 +1,7 @@ //HintName: UnionConverterAttribute.g.cs +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -10,9 +12,17 @@ sealed class UnionConverterAttribute : Attribute { public Type FromType { get; } public Type ToType { get; } +#if NETCOREAPP3_1_OR_GREATER public string? MethodName { get; } +#else + public string MethodName { get; } +#endif +#if NETCOREAPP3_1_OR_GREATER public UnionConverterAttribute(Type fromType, Type toType, string? methodName = null) +#else + public UnionConverterAttribute(Type fromType, Type toType, string methodName = null) +#endif { FromType = fromType; ToType = toType; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.FromConverterReportsDiagnostic#UnionConverterFromAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.FromConverterReportsDiagnostic#UnionConverterFromAttribute.g.verified.cs index d740ef3..222e936 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.FromConverterReportsDiagnostic#UnionConverterFromAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.FromConverterReportsDiagnostic#UnionConverterFromAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.FromConverterReportsDiagnostic#UnionConverterToAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.FromConverterReportsDiagnostic#UnionConverterToAttribute.g.verified.cs index fae1e4d..28901ff 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.FromConverterReportsDiagnostic#UnionConverterToAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.FromConverterReportsDiagnostic#UnionConverterToAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.FromConverterReportsDiagnostic#UnionTypeAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.FromConverterReportsDiagnostic#UnionTypeAttribute.g.verified.cs index 335ae09..927bc14 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.FromConverterReportsDiagnostic#UnionTypeAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.FromConverterReportsDiagnostic#UnionTypeAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -13,12 +15,24 @@ namespace N.SourceGenerators.UnionTypes internal sealed class UnionTypeAttribute : Attribute { public Type Type { get; } +#if NETCOREAPP3_1_OR_GREATER public string? Alias { get; } +#else + public string Alias { get; } +#endif public int Order { get; } public bool AllowNull { get; set; } +#if NETCOREAPP3_1_OR_GREATER public object? TypeDiscriminator { get; set; } +#else + public object TypeDiscriminator { get; set; } +#endif +#if NETCOREAPP3_1_OR_GREATER public UnionTypeAttribute(Type type, string? alias = null, [CallerLineNumber] int order = 0) +#else + public UnionTypeAttribute(Type type, string alias = null, [CallerLineNumber] int order = 0) +#endif { Type = type; Alias = alias; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.StaticExternalConverter#GenericUnionTypeAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.StaticExternalConverter#GenericUnionTypeAttribute.g.verified.cs index 9930562..17a28f9 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.StaticExternalConverter#GenericUnionTypeAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.StaticExternalConverter#GenericUnionTypeAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -12,8 +14,14 @@ namespace N.SourceGenerators.UnionTypes [AttributeUsage(AttributeTargets.GenericParameter, Inherited = false, AllowMultiple = false)] internal sealed class GenericUnionTypeAttribute : Attribute { +#if NETCOREAPP3_1_OR_GREATER public string? Alias { get; set; } public bool AllowNull { get; set; } public object? TypeDiscriminator { get; set; } +#else + public string Alias { get; set; } + public bool AllowNull { get; set; } + public object TypeDiscriminator { get; set; } +#endif } } \ No newline at end of file diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.StaticExternalConverter#JsonPolymorphicUnionAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.StaticExternalConverter#JsonPolymorphicUnionAttribute.g.verified.cs index e6b2d7c..ee781ad 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.StaticExternalConverter#JsonPolymorphicUnionAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.StaticExternalConverter#JsonPolymorphicUnionAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -12,6 +14,10 @@ namespace N.SourceGenerators.UnionTypes [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] internal sealed class JsonPolymorphicUnionAttribute : Attribute { +#if NETCOREAPP3_1_OR_GREATER public string? TypeDiscriminatorPropertyName { get; set; } +#else + public string TypeDiscriminatorPropertyName { get; set; } +#endif } } \ No newline at end of file diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.StaticExternalConverter#UnionConverterAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.StaticExternalConverter#UnionConverterAttribute.g.verified.cs index 3e6fd2b..973b6e2 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.StaticExternalConverter#UnionConverterAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.StaticExternalConverter#UnionConverterAttribute.g.verified.cs @@ -1,5 +1,7 @@ //HintName: UnionConverterAttribute.g.cs +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -10,9 +12,17 @@ sealed class UnionConverterAttribute : Attribute { public Type FromType { get; } public Type ToType { get; } +#if NETCOREAPP3_1_OR_GREATER public string? MethodName { get; } +#else + public string MethodName { get; } +#endif +#if NETCOREAPP3_1_OR_GREATER public UnionConverterAttribute(Type fromType, Type toType, string? methodName = null) +#else + public UnionConverterAttribute(Type fromType, Type toType, string methodName = null) +#endif { FromType = fromType; ToType = toType; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.StaticExternalConverter#UnionConverterFromAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.StaticExternalConverter#UnionConverterFromAttribute.g.verified.cs index d740ef3..222e936 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.StaticExternalConverter#UnionConverterFromAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.StaticExternalConverter#UnionConverterFromAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.StaticExternalConverter#UnionConverterToAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.StaticExternalConverter#UnionConverterToAttribute.g.verified.cs index fae1e4d..28901ff 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.StaticExternalConverter#UnionConverterToAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.StaticExternalConverter#UnionConverterToAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.StaticExternalConverter#UnionTypeAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.StaticExternalConverter#UnionTypeAttribute.g.verified.cs index 335ae09..927bc14 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.StaticExternalConverter#UnionTypeAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.StaticExternalConverter#UnionTypeAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -13,12 +15,24 @@ namespace N.SourceGenerators.UnionTypes internal sealed class UnionTypeAttribute : Attribute { public Type Type { get; } +#if NETCOREAPP3_1_OR_GREATER public string? Alias { get; } +#else + public string Alias { get; } +#endif public int Order { get; } public bool AllowNull { get; set; } +#if NETCOREAPP3_1_OR_GREATER public object? TypeDiscriminator { get; set; } +#else + public object TypeDiscriminator { get; set; } +#endif +#if NETCOREAPP3_1_OR_GREATER public UnionTypeAttribute(Type type, string? alias = null, [CallerLineNumber] int order = 0) +#else + public UnionTypeAttribute(Type type, string alias = null, [CallerLineNumber] int order = 0) +#endif { Type = type; Alias = alias; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.StaticExternalConverterReportsDiagnostic#GenericUnionTypeAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.StaticExternalConverterReportsDiagnostic#GenericUnionTypeAttribute.g.verified.cs index 9930562..17a28f9 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.StaticExternalConverterReportsDiagnostic#GenericUnionTypeAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.StaticExternalConverterReportsDiagnostic#GenericUnionTypeAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -12,8 +14,14 @@ namespace N.SourceGenerators.UnionTypes [AttributeUsage(AttributeTargets.GenericParameter, Inherited = false, AllowMultiple = false)] internal sealed class GenericUnionTypeAttribute : Attribute { +#if NETCOREAPP3_1_OR_GREATER public string? Alias { get; set; } public bool AllowNull { get; set; } public object? TypeDiscriminator { get; set; } +#else + public string Alias { get; set; } + public bool AllowNull { get; set; } + public object TypeDiscriminator { get; set; } +#endif } } \ No newline at end of file diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.StaticExternalConverterReportsDiagnostic#JsonPolymorphicUnionAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.StaticExternalConverterReportsDiagnostic#JsonPolymorphicUnionAttribute.g.verified.cs index e6b2d7c..ee781ad 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.StaticExternalConverterReportsDiagnostic#JsonPolymorphicUnionAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.StaticExternalConverterReportsDiagnostic#JsonPolymorphicUnionAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -12,6 +14,10 @@ namespace N.SourceGenerators.UnionTypes [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] internal sealed class JsonPolymorphicUnionAttribute : Attribute { +#if NETCOREAPP3_1_OR_GREATER public string? TypeDiscriminatorPropertyName { get; set; } +#else + public string TypeDiscriminatorPropertyName { get; set; } +#endif } } \ No newline at end of file diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.StaticExternalConverterReportsDiagnostic#UnionConverterAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.StaticExternalConverterReportsDiagnostic#UnionConverterAttribute.g.verified.cs index 3e6fd2b..973b6e2 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.StaticExternalConverterReportsDiagnostic#UnionConverterAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.StaticExternalConverterReportsDiagnostic#UnionConverterAttribute.g.verified.cs @@ -1,5 +1,7 @@ //HintName: UnionConverterAttribute.g.cs +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -10,9 +12,17 @@ sealed class UnionConverterAttribute : Attribute { public Type FromType { get; } public Type ToType { get; } +#if NETCOREAPP3_1_OR_GREATER public string? MethodName { get; } +#else + public string MethodName { get; } +#endif +#if NETCOREAPP3_1_OR_GREATER public UnionConverterAttribute(Type fromType, Type toType, string? methodName = null) +#else + public UnionConverterAttribute(Type fromType, Type toType, string methodName = null) +#endif { FromType = fromType; ToType = toType; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.StaticExternalConverterReportsDiagnostic#UnionConverterFromAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.StaticExternalConverterReportsDiagnostic#UnionConverterFromAttribute.g.verified.cs index d740ef3..222e936 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.StaticExternalConverterReportsDiagnostic#UnionConverterFromAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.StaticExternalConverterReportsDiagnostic#UnionConverterFromAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.StaticExternalConverterReportsDiagnostic#UnionConverterToAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.StaticExternalConverterReportsDiagnostic#UnionConverterToAttribute.g.verified.cs index fae1e4d..28901ff 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.StaticExternalConverterReportsDiagnostic#UnionConverterToAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.StaticExternalConverterReportsDiagnostic#UnionConverterToAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.StaticExternalConverterReportsDiagnostic#UnionTypeAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.StaticExternalConverterReportsDiagnostic#UnionTypeAttribute.g.verified.cs index 335ae09..927bc14 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.StaticExternalConverterReportsDiagnostic#UnionTypeAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.StaticExternalConverterReportsDiagnostic#UnionTypeAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -13,12 +15,24 @@ namespace N.SourceGenerators.UnionTypes internal sealed class UnionTypeAttribute : Attribute { public Type Type { get; } +#if NETCOREAPP3_1_OR_GREATER public string? Alias { get; } +#else + public string Alias { get; } +#endif public int Order { get; } public bool AllowNull { get; set; } +#if NETCOREAPP3_1_OR_GREATER public object? TypeDiscriminator { get; set; } +#else + public object TypeDiscriminator { get; set; } +#endif +#if NETCOREAPP3_1_OR_GREATER public UnionTypeAttribute(Type type, string? alias = null, [CallerLineNumber] int order = 0) +#else + public UnionTypeAttribute(Type type, string alias = null, [CallerLineNumber] int order = 0) +#endif { Type = type; Alias = alias; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ToConverter#GenericUnionTypeAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ToConverter#GenericUnionTypeAttribute.g.verified.cs index 9930562..17a28f9 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ToConverter#GenericUnionTypeAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ToConverter#GenericUnionTypeAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -12,8 +14,14 @@ namespace N.SourceGenerators.UnionTypes [AttributeUsage(AttributeTargets.GenericParameter, Inherited = false, AllowMultiple = false)] internal sealed class GenericUnionTypeAttribute : Attribute { +#if NETCOREAPP3_1_OR_GREATER public string? Alias { get; set; } public bool AllowNull { get; set; } public object? TypeDiscriminator { get; set; } +#else + public string Alias { get; set; } + public bool AllowNull { get; set; } + public object TypeDiscriminator { get; set; } +#endif } } \ No newline at end of file diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ToConverter#JsonPolymorphicUnionAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ToConverter#JsonPolymorphicUnionAttribute.g.verified.cs index e6b2d7c..ee781ad 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ToConverter#JsonPolymorphicUnionAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ToConverter#JsonPolymorphicUnionAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -12,6 +14,10 @@ namespace N.SourceGenerators.UnionTypes [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] internal sealed class JsonPolymorphicUnionAttribute : Attribute { +#if NETCOREAPP3_1_OR_GREATER public string? TypeDiscriminatorPropertyName { get; set; } +#else + public string TypeDiscriminatorPropertyName { get; set; } +#endif } } \ No newline at end of file diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ToConverter#UnionConverterAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ToConverter#UnionConverterAttribute.g.verified.cs index 3e6fd2b..973b6e2 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ToConverter#UnionConverterAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ToConverter#UnionConverterAttribute.g.verified.cs @@ -1,5 +1,7 @@ //HintName: UnionConverterAttribute.g.cs +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -10,9 +12,17 @@ sealed class UnionConverterAttribute : Attribute { public Type FromType { get; } public Type ToType { get; } +#if NETCOREAPP3_1_OR_GREATER public string? MethodName { get; } +#else + public string MethodName { get; } +#endif +#if NETCOREAPP3_1_OR_GREATER public UnionConverterAttribute(Type fromType, Type toType, string? methodName = null) +#else + public UnionConverterAttribute(Type fromType, Type toType, string methodName = null) +#endif { FromType = fromType; ToType = toType; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ToConverter#UnionConverterFromAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ToConverter#UnionConverterFromAttribute.g.verified.cs index d740ef3..222e936 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ToConverter#UnionConverterFromAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ToConverter#UnionConverterFromAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ToConverter#UnionConverterToAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ToConverter#UnionConverterToAttribute.g.verified.cs index fae1e4d..28901ff 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ToConverter#UnionConverterToAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ToConverter#UnionConverterToAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ToConverter#UnionTypeAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ToConverter#UnionTypeAttribute.g.verified.cs index 335ae09..927bc14 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ToConverter#UnionTypeAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ToConverter#UnionTypeAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -13,12 +15,24 @@ namespace N.SourceGenerators.UnionTypes internal sealed class UnionTypeAttribute : Attribute { public Type Type { get; } +#if NETCOREAPP3_1_OR_GREATER public string? Alias { get; } +#else + public string Alias { get; } +#endif public int Order { get; } public bool AllowNull { get; set; } +#if NETCOREAPP3_1_OR_GREATER public object? TypeDiscriminator { get; set; } +#else + public object TypeDiscriminator { get; set; } +#endif +#if NETCOREAPP3_1_OR_GREATER public UnionTypeAttribute(Type type, string? alias = null, [CallerLineNumber] int order = 0) +#else + public UnionTypeAttribute(Type type, string alias = null, [CallerLineNumber] int order = 0) +#endif { Type = type; Alias = alias; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ToConverterReportsDiagnostic#GenericUnionTypeAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ToConverterReportsDiagnostic#GenericUnionTypeAttribute.g.verified.cs index 9930562..17a28f9 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ToConverterReportsDiagnostic#GenericUnionTypeAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ToConverterReportsDiagnostic#GenericUnionTypeAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -12,8 +14,14 @@ namespace N.SourceGenerators.UnionTypes [AttributeUsage(AttributeTargets.GenericParameter, Inherited = false, AllowMultiple = false)] internal sealed class GenericUnionTypeAttribute : Attribute { +#if NETCOREAPP3_1_OR_GREATER public string? Alias { get; set; } public bool AllowNull { get; set; } public object? TypeDiscriminator { get; set; } +#else + public string Alias { get; set; } + public bool AllowNull { get; set; } + public object TypeDiscriminator { get; set; } +#endif } } \ No newline at end of file diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ToConverterReportsDiagnostic#JsonPolymorphicUnionAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ToConverterReportsDiagnostic#JsonPolymorphicUnionAttribute.g.verified.cs index e6b2d7c..ee781ad 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ToConverterReportsDiagnostic#JsonPolymorphicUnionAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ToConverterReportsDiagnostic#JsonPolymorphicUnionAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -12,6 +14,10 @@ namespace N.SourceGenerators.UnionTypes [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] internal sealed class JsonPolymorphicUnionAttribute : Attribute { +#if NETCOREAPP3_1_OR_GREATER public string? TypeDiscriminatorPropertyName { get; set; } +#else + public string TypeDiscriminatorPropertyName { get; set; } +#endif } } \ No newline at end of file diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ToConverterReportsDiagnostic#UnionConverterAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ToConverterReportsDiagnostic#UnionConverterAttribute.g.verified.cs index 3e6fd2b..973b6e2 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ToConverterReportsDiagnostic#UnionConverterAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ToConverterReportsDiagnostic#UnionConverterAttribute.g.verified.cs @@ -1,5 +1,7 @@ //HintName: UnionConverterAttribute.g.cs +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -10,9 +12,17 @@ sealed class UnionConverterAttribute : Attribute { public Type FromType { get; } public Type ToType { get; } +#if NETCOREAPP3_1_OR_GREATER public string? MethodName { get; } +#else + public string MethodName { get; } +#endif +#if NETCOREAPP3_1_OR_GREATER public UnionConverterAttribute(Type fromType, Type toType, string? methodName = null) +#else + public UnionConverterAttribute(Type fromType, Type toType, string methodName = null) +#endif { FromType = fromType; ToType = toType; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ToConverterReportsDiagnostic#UnionConverterFromAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ToConverterReportsDiagnostic#UnionConverterFromAttribute.g.verified.cs index d740ef3..222e936 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ToConverterReportsDiagnostic#UnionConverterFromAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ToConverterReportsDiagnostic#UnionConverterFromAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ToConverterReportsDiagnostic#UnionConverterToAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ToConverterReportsDiagnostic#UnionConverterToAttribute.g.verified.cs index fae1e4d..28901ff 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ToConverterReportsDiagnostic#UnionConverterToAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ToConverterReportsDiagnostic#UnionConverterToAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ToConverterReportsDiagnostic#UnionTypeAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ToConverterReportsDiagnostic#UnionTypeAttribute.g.verified.cs index 335ae09..927bc14 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ToConverterReportsDiagnostic#UnionTypeAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/ConverterGeneratorTests.ToConverterReportsDiagnostic#UnionTypeAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -13,12 +15,24 @@ namespace N.SourceGenerators.UnionTypes internal sealed class UnionTypeAttribute : Attribute { public Type Type { get; } +#if NETCOREAPP3_1_OR_GREATER public string? Alias { get; } +#else + public string Alias { get; } +#endif public int Order { get; } public bool AllowNull { get; set; } +#if NETCOREAPP3_1_OR_GREATER public object? TypeDiscriminator { get; set; } +#else + public object TypeDiscriminator { get; set; } +#endif +#if NETCOREAPP3_1_OR_GREATER public UnionTypeAttribute(Type type, string? alias = null, [CallerLineNumber] int order = 0) +#else + public UnionTypeAttribute(Type type, string alias = null, [CallerLineNumber] int order = 0) +#endif { Type = type; Alias = alias; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.InvalidTypeReportsAllDiagnostics#GenericUnionTypeAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.InvalidTypeReportsAllDiagnostics#GenericUnionTypeAttribute.g.verified.cs index 9930562..17a28f9 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.InvalidTypeReportsAllDiagnostics#GenericUnionTypeAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.InvalidTypeReportsAllDiagnostics#GenericUnionTypeAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -12,8 +14,14 @@ namespace N.SourceGenerators.UnionTypes [AttributeUsage(AttributeTargets.GenericParameter, Inherited = false, AllowMultiple = false)] internal sealed class GenericUnionTypeAttribute : Attribute { +#if NETCOREAPP3_1_OR_GREATER public string? Alias { get; set; } public bool AllowNull { get; set; } public object? TypeDiscriminator { get; set; } +#else + public string Alias { get; set; } + public bool AllowNull { get; set; } + public object TypeDiscriminator { get; set; } +#endif } } \ No newline at end of file diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.InvalidTypeReportsAllDiagnostics#JsonPolymorphicUnionAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.InvalidTypeReportsAllDiagnostics#JsonPolymorphicUnionAttribute.g.verified.cs index e6b2d7c..ee781ad 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.InvalidTypeReportsAllDiagnostics#JsonPolymorphicUnionAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.InvalidTypeReportsAllDiagnostics#JsonPolymorphicUnionAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -12,6 +14,10 @@ namespace N.SourceGenerators.UnionTypes [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] internal sealed class JsonPolymorphicUnionAttribute : Attribute { +#if NETCOREAPP3_1_OR_GREATER public string? TypeDiscriminatorPropertyName { get; set; } +#else + public string TypeDiscriminatorPropertyName { get; set; } +#endif } } \ No newline at end of file diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.InvalidTypeReportsAllDiagnostics#UnionConverterAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.InvalidTypeReportsAllDiagnostics#UnionConverterAttribute.g.verified.cs index 3e6fd2b..973b6e2 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.InvalidTypeReportsAllDiagnostics#UnionConverterAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.InvalidTypeReportsAllDiagnostics#UnionConverterAttribute.g.verified.cs @@ -1,5 +1,7 @@ //HintName: UnionConverterAttribute.g.cs +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -10,9 +12,17 @@ sealed class UnionConverterAttribute : Attribute { public Type FromType { get; } public Type ToType { get; } +#if NETCOREAPP3_1_OR_GREATER public string? MethodName { get; } +#else + public string MethodName { get; } +#endif +#if NETCOREAPP3_1_OR_GREATER public UnionConverterAttribute(Type fromType, Type toType, string? methodName = null) +#else + public UnionConverterAttribute(Type fromType, Type toType, string methodName = null) +#endif { FromType = fromType; ToType = toType; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.InvalidTypeReportsAllDiagnostics#UnionConverterFromAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.InvalidTypeReportsAllDiagnostics#UnionConverterFromAttribute.g.verified.cs index d740ef3..222e936 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.InvalidTypeReportsAllDiagnostics#UnionConverterFromAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.InvalidTypeReportsAllDiagnostics#UnionConverterFromAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.InvalidTypeReportsAllDiagnostics#UnionConverterToAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.InvalidTypeReportsAllDiagnostics#UnionConverterToAttribute.g.verified.cs index fae1e4d..28901ff 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.InvalidTypeReportsAllDiagnostics#UnionConverterToAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.InvalidTypeReportsAllDiagnostics#UnionConverterToAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.InvalidTypeReportsAllDiagnostics#UnionTypeAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.InvalidTypeReportsAllDiagnostics#UnionTypeAttribute.g.verified.cs index 335ae09..927bc14 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.InvalidTypeReportsAllDiagnostics#UnionTypeAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.InvalidTypeReportsAllDiagnostics#UnionTypeAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -13,12 +15,24 @@ namespace N.SourceGenerators.UnionTypes internal sealed class UnionTypeAttribute : Attribute { public Type Type { get; } +#if NETCOREAPP3_1_OR_GREATER public string? Alias { get; } +#else + public string Alias { get; } +#endif public int Order { get; } public bool AllowNull { get; set; } +#if NETCOREAPP3_1_OR_GREATER public object? TypeDiscriminator { get; set; } +#else + public object TypeDiscriminator { get; set; } +#endif +#if NETCOREAPP3_1_OR_GREATER public UnionTypeAttribute(Type type, string? alias = null, [CallerLineNumber] int order = 0) +#else + public UnionTypeAttribute(Type type, string alias = null, [CallerLineNumber] int order = 0) +#endif { Type = type; Alias = alias; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.NotPartialTypeReportsDiagnostics#GenericUnionTypeAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.NotPartialTypeReportsDiagnostics#GenericUnionTypeAttribute.g.verified.cs index 9930562..17a28f9 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.NotPartialTypeReportsDiagnostics#GenericUnionTypeAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.NotPartialTypeReportsDiagnostics#GenericUnionTypeAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -12,8 +14,14 @@ namespace N.SourceGenerators.UnionTypes [AttributeUsage(AttributeTargets.GenericParameter, Inherited = false, AllowMultiple = false)] internal sealed class GenericUnionTypeAttribute : Attribute { +#if NETCOREAPP3_1_OR_GREATER public string? Alias { get; set; } public bool AllowNull { get; set; } public object? TypeDiscriminator { get; set; } +#else + public string Alias { get; set; } + public bool AllowNull { get; set; } + public object TypeDiscriminator { get; set; } +#endif } } \ No newline at end of file diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.NotPartialTypeReportsDiagnostics#JsonPolymorphicUnionAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.NotPartialTypeReportsDiagnostics#JsonPolymorphicUnionAttribute.g.verified.cs index e6b2d7c..ee781ad 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.NotPartialTypeReportsDiagnostics#JsonPolymorphicUnionAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.NotPartialTypeReportsDiagnostics#JsonPolymorphicUnionAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -12,6 +14,10 @@ namespace N.SourceGenerators.UnionTypes [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] internal sealed class JsonPolymorphicUnionAttribute : Attribute { +#if NETCOREAPP3_1_OR_GREATER public string? TypeDiscriminatorPropertyName { get; set; } +#else + public string TypeDiscriminatorPropertyName { get; set; } +#endif } } \ No newline at end of file diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.NotPartialTypeReportsDiagnostics#UnionConverterAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.NotPartialTypeReportsDiagnostics#UnionConverterAttribute.g.verified.cs index 3e6fd2b..973b6e2 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.NotPartialTypeReportsDiagnostics#UnionConverterAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.NotPartialTypeReportsDiagnostics#UnionConverterAttribute.g.verified.cs @@ -1,5 +1,7 @@ //HintName: UnionConverterAttribute.g.cs +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -10,9 +12,17 @@ sealed class UnionConverterAttribute : Attribute { public Type FromType { get; } public Type ToType { get; } +#if NETCOREAPP3_1_OR_GREATER public string? MethodName { get; } +#else + public string MethodName { get; } +#endif +#if NETCOREAPP3_1_OR_GREATER public UnionConverterAttribute(Type fromType, Type toType, string? methodName = null) +#else + public UnionConverterAttribute(Type fromType, Type toType, string methodName = null) +#endif { FromType = fromType; ToType = toType; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.NotPartialTypeReportsDiagnostics#UnionConverterFromAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.NotPartialTypeReportsDiagnostics#UnionConverterFromAttribute.g.verified.cs index d740ef3..222e936 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.NotPartialTypeReportsDiagnostics#UnionConverterFromAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.NotPartialTypeReportsDiagnostics#UnionConverterFromAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.NotPartialTypeReportsDiagnostics#UnionConverterToAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.NotPartialTypeReportsDiagnostics#UnionConverterToAttribute.g.verified.cs index fae1e4d..28901ff 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.NotPartialTypeReportsDiagnostics#UnionConverterToAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.NotPartialTypeReportsDiagnostics#UnionConverterToAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.NotPartialTypeReportsDiagnostics#UnionTypeAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.NotPartialTypeReportsDiagnostics#UnionTypeAttribute.g.verified.cs index 335ae09..927bc14 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.NotPartialTypeReportsDiagnostics#UnionTypeAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.NotPartialTypeReportsDiagnostics#UnionTypeAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -13,12 +15,24 @@ namespace N.SourceGenerators.UnionTypes internal sealed class UnionTypeAttribute : Attribute { public Type Type { get; } +#if NETCOREAPP3_1_OR_GREATER public string? Alias { get; } +#else + public string Alias { get; } +#endif public int Order { get; } public bool AllowNull { get; set; } +#if NETCOREAPP3_1_OR_GREATER public object? TypeDiscriminator { get; set; } +#else + public object TypeDiscriminator { get; set; } +#endif +#if NETCOREAPP3_1_OR_GREATER public UnionTypeAttribute(Type type, string? alias = null, [CallerLineNumber] int order = 0) +#else + public UnionTypeAttribute(Type type, string alias = null, [CallerLineNumber] int order = 0) +#endif { Type = type; Alias = alias; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.VariantAliasDuplicateReportsDiagnostics#GenericUnionTypeAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.VariantAliasDuplicateReportsDiagnostics#GenericUnionTypeAttribute.g.verified.cs index 9930562..17a28f9 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.VariantAliasDuplicateReportsDiagnostics#GenericUnionTypeAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.VariantAliasDuplicateReportsDiagnostics#GenericUnionTypeAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -12,8 +14,14 @@ namespace N.SourceGenerators.UnionTypes [AttributeUsage(AttributeTargets.GenericParameter, Inherited = false, AllowMultiple = false)] internal sealed class GenericUnionTypeAttribute : Attribute { +#if NETCOREAPP3_1_OR_GREATER public string? Alias { get; set; } public bool AllowNull { get; set; } public object? TypeDiscriminator { get; set; } +#else + public string Alias { get; set; } + public bool AllowNull { get; set; } + public object TypeDiscriminator { get; set; } +#endif } } \ No newline at end of file diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.VariantAliasDuplicateReportsDiagnostics#JsonPolymorphicUnionAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.VariantAliasDuplicateReportsDiagnostics#JsonPolymorphicUnionAttribute.g.verified.cs index e6b2d7c..ee781ad 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.VariantAliasDuplicateReportsDiagnostics#JsonPolymorphicUnionAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.VariantAliasDuplicateReportsDiagnostics#JsonPolymorphicUnionAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -12,6 +14,10 @@ namespace N.SourceGenerators.UnionTypes [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] internal sealed class JsonPolymorphicUnionAttribute : Attribute { +#if NETCOREAPP3_1_OR_GREATER public string? TypeDiscriminatorPropertyName { get; set; } +#else + public string TypeDiscriminatorPropertyName { get; set; } +#endif } } \ No newline at end of file diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.VariantAliasDuplicateReportsDiagnostics#UnionConverterAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.VariantAliasDuplicateReportsDiagnostics#UnionConverterAttribute.g.verified.cs index 3e6fd2b..973b6e2 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.VariantAliasDuplicateReportsDiagnostics#UnionConverterAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.VariantAliasDuplicateReportsDiagnostics#UnionConverterAttribute.g.verified.cs @@ -1,5 +1,7 @@ //HintName: UnionConverterAttribute.g.cs +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -10,9 +12,17 @@ sealed class UnionConverterAttribute : Attribute { public Type FromType { get; } public Type ToType { get; } +#if NETCOREAPP3_1_OR_GREATER public string? MethodName { get; } +#else + public string MethodName { get; } +#endif +#if NETCOREAPP3_1_OR_GREATER public UnionConverterAttribute(Type fromType, Type toType, string? methodName = null) +#else + public UnionConverterAttribute(Type fromType, Type toType, string methodName = null) +#endif { FromType = fromType; ToType = toType; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.VariantAliasDuplicateReportsDiagnostics#UnionConverterFromAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.VariantAliasDuplicateReportsDiagnostics#UnionConverterFromAttribute.g.verified.cs index d740ef3..222e936 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.VariantAliasDuplicateReportsDiagnostics#UnionConverterFromAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.VariantAliasDuplicateReportsDiagnostics#UnionConverterFromAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.VariantAliasDuplicateReportsDiagnostics#UnionConverterToAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.VariantAliasDuplicateReportsDiagnostics#UnionConverterToAttribute.g.verified.cs index fae1e4d..28901ff 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.VariantAliasDuplicateReportsDiagnostics#UnionConverterToAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.VariantAliasDuplicateReportsDiagnostics#UnionConverterToAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.VariantAliasDuplicateReportsDiagnostics#UnionTypeAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.VariantAliasDuplicateReportsDiagnostics#UnionTypeAttribute.g.verified.cs index 335ae09..927bc14 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.VariantAliasDuplicateReportsDiagnostics#UnionTypeAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.VariantAliasDuplicateReportsDiagnostics#UnionTypeAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -13,12 +15,24 @@ namespace N.SourceGenerators.UnionTypes internal sealed class UnionTypeAttribute : Attribute { public Type Type { get; } +#if NETCOREAPP3_1_OR_GREATER public string? Alias { get; } +#else + public string Alias { get; } +#endif public int Order { get; } public bool AllowNull { get; set; } +#if NETCOREAPP3_1_OR_GREATER public object? TypeDiscriminator { get; set; } +#else + public object TypeDiscriminator { get; set; } +#endif +#if NETCOREAPP3_1_OR_GREATER public UnionTypeAttribute(Type type, string? alias = null, [CallerLineNumber] int order = 0) +#else + public UnionTypeAttribute(Type type, string alias = null, [CallerLineNumber] int order = 0) +#endif { Type = type; Alias = alias; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.VariantOrderDuplicateReportsDiagnostics#GenericUnionTypeAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.VariantOrderDuplicateReportsDiagnostics#GenericUnionTypeAttribute.g.verified.cs index 9930562..17a28f9 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.VariantOrderDuplicateReportsDiagnostics#GenericUnionTypeAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.VariantOrderDuplicateReportsDiagnostics#GenericUnionTypeAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -12,8 +14,14 @@ namespace N.SourceGenerators.UnionTypes [AttributeUsage(AttributeTargets.GenericParameter, Inherited = false, AllowMultiple = false)] internal sealed class GenericUnionTypeAttribute : Attribute { +#if NETCOREAPP3_1_OR_GREATER public string? Alias { get; set; } public bool AllowNull { get; set; } public object? TypeDiscriminator { get; set; } +#else + public string Alias { get; set; } + public bool AllowNull { get; set; } + public object TypeDiscriminator { get; set; } +#endif } } \ No newline at end of file diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.VariantOrderDuplicateReportsDiagnostics#JsonPolymorphicUnionAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.VariantOrderDuplicateReportsDiagnostics#JsonPolymorphicUnionAttribute.g.verified.cs index e6b2d7c..ee781ad 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.VariantOrderDuplicateReportsDiagnostics#JsonPolymorphicUnionAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.VariantOrderDuplicateReportsDiagnostics#JsonPolymorphicUnionAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -12,6 +14,10 @@ namespace N.SourceGenerators.UnionTypes [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] internal sealed class JsonPolymorphicUnionAttribute : Attribute { +#if NETCOREAPP3_1_OR_GREATER public string? TypeDiscriminatorPropertyName { get; set; } +#else + public string TypeDiscriminatorPropertyName { get; set; } +#endif } } \ No newline at end of file diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.VariantOrderDuplicateReportsDiagnostics#UnionConverterAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.VariantOrderDuplicateReportsDiagnostics#UnionConverterAttribute.g.verified.cs index 3e6fd2b..973b6e2 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.VariantOrderDuplicateReportsDiagnostics#UnionConverterAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.VariantOrderDuplicateReportsDiagnostics#UnionConverterAttribute.g.verified.cs @@ -1,5 +1,7 @@ //HintName: UnionConverterAttribute.g.cs +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -10,9 +12,17 @@ sealed class UnionConverterAttribute : Attribute { public Type FromType { get; } public Type ToType { get; } +#if NETCOREAPP3_1_OR_GREATER public string? MethodName { get; } +#else + public string MethodName { get; } +#endif +#if NETCOREAPP3_1_OR_GREATER public UnionConverterAttribute(Type fromType, Type toType, string? methodName = null) +#else + public UnionConverterAttribute(Type fromType, Type toType, string methodName = null) +#endif { FromType = fromType; ToType = toType; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.VariantOrderDuplicateReportsDiagnostics#UnionConverterFromAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.VariantOrderDuplicateReportsDiagnostics#UnionConverterFromAttribute.g.verified.cs index d740ef3..222e936 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.VariantOrderDuplicateReportsDiagnostics#UnionConverterFromAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.VariantOrderDuplicateReportsDiagnostics#UnionConverterFromAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.VariantOrderDuplicateReportsDiagnostics#UnionConverterToAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.VariantOrderDuplicateReportsDiagnostics#UnionConverterToAttribute.g.verified.cs index fae1e4d..28901ff 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.VariantOrderDuplicateReportsDiagnostics#UnionConverterToAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.VariantOrderDuplicateReportsDiagnostics#UnionConverterToAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.VariantOrderDuplicateReportsDiagnostics#UnionTypeAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.VariantOrderDuplicateReportsDiagnostics#UnionTypeAttribute.g.verified.cs index 335ae09..927bc14 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.VariantOrderDuplicateReportsDiagnostics#UnionTypeAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.VariantOrderDuplicateReportsDiagnostics#UnionTypeAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -13,12 +15,24 @@ namespace N.SourceGenerators.UnionTypes internal sealed class UnionTypeAttribute : Attribute { public Type Type { get; } +#if NETCOREAPP3_1_OR_GREATER public string? Alias { get; } +#else + public string Alias { get; } +#endif public int Order { get; } public bool AllowNull { get; set; } +#if NETCOREAPP3_1_OR_GREATER public object? TypeDiscriminator { get; set; } +#else + public object TypeDiscriminator { get; set; } +#endif +#if NETCOREAPP3_1_OR_GREATER public UnionTypeAttribute(Type type, string? alias = null, [CallerLineNumber] int order = 0) +#else + public UnionTypeAttribute(Type type, string alias = null, [CallerLineNumber] int order = 0) +#endif { Type = type; Alias = alias; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.VariantTypeDuplicateReportsDiagnostics#GenericUnionTypeAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.VariantTypeDuplicateReportsDiagnostics#GenericUnionTypeAttribute.g.verified.cs index 9930562..17a28f9 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.VariantTypeDuplicateReportsDiagnostics#GenericUnionTypeAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.VariantTypeDuplicateReportsDiagnostics#GenericUnionTypeAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -12,8 +14,14 @@ namespace N.SourceGenerators.UnionTypes [AttributeUsage(AttributeTargets.GenericParameter, Inherited = false, AllowMultiple = false)] internal sealed class GenericUnionTypeAttribute : Attribute { +#if NETCOREAPP3_1_OR_GREATER public string? Alias { get; set; } public bool AllowNull { get; set; } public object? TypeDiscriminator { get; set; } +#else + public string Alias { get; set; } + public bool AllowNull { get; set; } + public object TypeDiscriminator { get; set; } +#endif } } \ No newline at end of file diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.VariantTypeDuplicateReportsDiagnostics#JsonPolymorphicUnionAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.VariantTypeDuplicateReportsDiagnostics#JsonPolymorphicUnionAttribute.g.verified.cs index e6b2d7c..ee781ad 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.VariantTypeDuplicateReportsDiagnostics#JsonPolymorphicUnionAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.VariantTypeDuplicateReportsDiagnostics#JsonPolymorphicUnionAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -12,6 +14,10 @@ namespace N.SourceGenerators.UnionTypes [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] internal sealed class JsonPolymorphicUnionAttribute : Attribute { +#if NETCOREAPP3_1_OR_GREATER public string? TypeDiscriminatorPropertyName { get; set; } +#else + public string TypeDiscriminatorPropertyName { get; set; } +#endif } } \ No newline at end of file diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.VariantTypeDuplicateReportsDiagnostics#UnionConverterAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.VariantTypeDuplicateReportsDiagnostics#UnionConverterAttribute.g.verified.cs index 3e6fd2b..973b6e2 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.VariantTypeDuplicateReportsDiagnostics#UnionConverterAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.VariantTypeDuplicateReportsDiagnostics#UnionConverterAttribute.g.verified.cs @@ -1,5 +1,7 @@ //HintName: UnionConverterAttribute.g.cs +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -10,9 +12,17 @@ sealed class UnionConverterAttribute : Attribute { public Type FromType { get; } public Type ToType { get; } +#if NETCOREAPP3_1_OR_GREATER public string? MethodName { get; } +#else + public string MethodName { get; } +#endif +#if NETCOREAPP3_1_OR_GREATER public UnionConverterAttribute(Type fromType, Type toType, string? methodName = null) +#else + public UnionConverterAttribute(Type fromType, Type toType, string methodName = null) +#endif { FromType = fromType; ToType = toType; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.VariantTypeDuplicateReportsDiagnostics#UnionConverterFromAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.VariantTypeDuplicateReportsDiagnostics#UnionConverterFromAttribute.g.verified.cs index d740ef3..222e936 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.VariantTypeDuplicateReportsDiagnostics#UnionConverterFromAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.VariantTypeDuplicateReportsDiagnostics#UnionConverterFromAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.VariantTypeDuplicateReportsDiagnostics#UnionConverterToAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.VariantTypeDuplicateReportsDiagnostics#UnionConverterToAttribute.g.verified.cs index fae1e4d..28901ff 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.VariantTypeDuplicateReportsDiagnostics#UnionConverterToAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.VariantTypeDuplicateReportsDiagnostics#UnionConverterToAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.VariantTypeDuplicateReportsDiagnostics#UnionTypeAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.VariantTypeDuplicateReportsDiagnostics#UnionTypeAttribute.g.verified.cs index 335ae09..927bc14 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.VariantTypeDuplicateReportsDiagnostics#UnionTypeAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/DiagnosticTests.VariantTypeDuplicateReportsDiagnostics#UnionTypeAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -13,12 +15,24 @@ namespace N.SourceGenerators.UnionTypes internal sealed class UnionTypeAttribute : Attribute { public Type Type { get; } +#if NETCOREAPP3_1_OR_GREATER public string? Alias { get; } +#else + public string Alias { get; } +#endif public int Order { get; } public bool AllowNull { get; set; } +#if NETCOREAPP3_1_OR_GREATER public object? TypeDiscriminator { get; set; } +#else + public object TypeDiscriminator { get; set; } +#endif +#if NETCOREAPP3_1_OR_GREATER public UnionTypeAttribute(Type type, string? alias = null, [CallerLineNumber] int order = 0) +#else + public UnionTypeAttribute(Type type, string alias = null, [CallerLineNumber] int order = 0) +#endif { Type = type; Alias = alias; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DifferentNamespaces#GenericUnionTypeAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DifferentNamespaces#GenericUnionTypeAttribute.g.verified.cs index 9930562..17a28f9 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DifferentNamespaces#GenericUnionTypeAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DifferentNamespaces#GenericUnionTypeAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -12,8 +14,14 @@ namespace N.SourceGenerators.UnionTypes [AttributeUsage(AttributeTargets.GenericParameter, Inherited = false, AllowMultiple = false)] internal sealed class GenericUnionTypeAttribute : Attribute { +#if NETCOREAPP3_1_OR_GREATER public string? Alias { get; set; } public bool AllowNull { get; set; } public object? TypeDiscriminator { get; set; } +#else + public string Alias { get; set; } + public bool AllowNull { get; set; } + public object TypeDiscriminator { get; set; } +#endif } } \ No newline at end of file diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DifferentNamespaces#JsonPolymorphicUnionAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DifferentNamespaces#JsonPolymorphicUnionAttribute.g.verified.cs index e6b2d7c..ee781ad 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DifferentNamespaces#JsonPolymorphicUnionAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DifferentNamespaces#JsonPolymorphicUnionAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -12,6 +14,10 @@ namespace N.SourceGenerators.UnionTypes [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] internal sealed class JsonPolymorphicUnionAttribute : Attribute { +#if NETCOREAPP3_1_OR_GREATER public string? TypeDiscriminatorPropertyName { get; set; } +#else + public string TypeDiscriminatorPropertyName { get; set; } +#endif } } \ No newline at end of file diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DifferentNamespaces#UnionConverterAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DifferentNamespaces#UnionConverterAttribute.g.verified.cs index 3e6fd2b..973b6e2 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DifferentNamespaces#UnionConverterAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DifferentNamespaces#UnionConverterAttribute.g.verified.cs @@ -1,5 +1,7 @@ //HintName: UnionConverterAttribute.g.cs +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -10,9 +12,17 @@ sealed class UnionConverterAttribute : Attribute { public Type FromType { get; } public Type ToType { get; } +#if NETCOREAPP3_1_OR_GREATER public string? MethodName { get; } +#else + public string MethodName { get; } +#endif +#if NETCOREAPP3_1_OR_GREATER public UnionConverterAttribute(Type fromType, Type toType, string? methodName = null) +#else + public UnionConverterAttribute(Type fromType, Type toType, string methodName = null) +#endif { FromType = fromType; ToType = toType; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DifferentNamespaces#UnionConverterFromAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DifferentNamespaces#UnionConverterFromAttribute.g.verified.cs index d740ef3..222e936 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DifferentNamespaces#UnionConverterFromAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DifferentNamespaces#UnionConverterFromAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DifferentNamespaces#UnionConverterToAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DifferentNamespaces#UnionConverterToAttribute.g.verified.cs index fae1e4d..28901ff 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DifferentNamespaces#UnionConverterToAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DifferentNamespaces#UnionConverterToAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DifferentNamespaces#UnionTypeAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DifferentNamespaces#UnionTypeAttribute.g.verified.cs index 335ae09..927bc14 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DifferentNamespaces#UnionTypeAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DifferentNamespaces#UnionTypeAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -13,12 +15,24 @@ namespace N.SourceGenerators.UnionTypes internal sealed class UnionTypeAttribute : Attribute { public Type Type { get; } +#if NETCOREAPP3_1_OR_GREATER public string? Alias { get; } +#else + public string Alias { get; } +#endif public int Order { get; } public bool AllowNull { get; set; } +#if NETCOREAPP3_1_OR_GREATER public object? TypeDiscriminator { get; set; } +#else + public object TypeDiscriminator { get; set; } +#endif +#if NETCOREAPP3_1_OR_GREATER public UnionTypeAttribute(Type type, string? alias = null, [CallerLineNumber] int order = 0) +#else + public UnionTypeAttribute(Type type, string alias = null, [CallerLineNumber] int order = 0) +#endif { Type = type; Alias = alias; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DoNotOverrideToString_partial-class#GenericUnionTypeAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DoNotOverrideToString_partial-class#GenericUnionTypeAttribute.g.verified.cs index 9930562..17a28f9 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DoNotOverrideToString_partial-class#GenericUnionTypeAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DoNotOverrideToString_partial-class#GenericUnionTypeAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -12,8 +14,14 @@ namespace N.SourceGenerators.UnionTypes [AttributeUsage(AttributeTargets.GenericParameter, Inherited = false, AllowMultiple = false)] internal sealed class GenericUnionTypeAttribute : Attribute { +#if NETCOREAPP3_1_OR_GREATER public string? Alias { get; set; } public bool AllowNull { get; set; } public object? TypeDiscriminator { get; set; } +#else + public string Alias { get; set; } + public bool AllowNull { get; set; } + public object TypeDiscriminator { get; set; } +#endif } } \ No newline at end of file diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DoNotOverrideToString_partial-class#JsonPolymorphicUnionAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DoNotOverrideToString_partial-class#JsonPolymorphicUnionAttribute.g.verified.cs index e6b2d7c..ee781ad 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DoNotOverrideToString_partial-class#JsonPolymorphicUnionAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DoNotOverrideToString_partial-class#JsonPolymorphicUnionAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -12,6 +14,10 @@ namespace N.SourceGenerators.UnionTypes [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] internal sealed class JsonPolymorphicUnionAttribute : Attribute { +#if NETCOREAPP3_1_OR_GREATER public string? TypeDiscriminatorPropertyName { get; set; } +#else + public string TypeDiscriminatorPropertyName { get; set; } +#endif } } \ No newline at end of file diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DoNotOverrideToString_partial-class#UnionConverterAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DoNotOverrideToString_partial-class#UnionConverterAttribute.g.verified.cs index 3e6fd2b..973b6e2 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DoNotOverrideToString_partial-class#UnionConverterAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DoNotOverrideToString_partial-class#UnionConverterAttribute.g.verified.cs @@ -1,5 +1,7 @@ //HintName: UnionConverterAttribute.g.cs +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -10,9 +12,17 @@ sealed class UnionConverterAttribute : Attribute { public Type FromType { get; } public Type ToType { get; } +#if NETCOREAPP3_1_OR_GREATER public string? MethodName { get; } +#else + public string MethodName { get; } +#endif +#if NETCOREAPP3_1_OR_GREATER public UnionConverterAttribute(Type fromType, Type toType, string? methodName = null) +#else + public UnionConverterAttribute(Type fromType, Type toType, string methodName = null) +#endif { FromType = fromType; ToType = toType; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DoNotOverrideToString_partial-class#UnionConverterFromAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DoNotOverrideToString_partial-class#UnionConverterFromAttribute.g.verified.cs index d740ef3..222e936 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DoNotOverrideToString_partial-class#UnionConverterFromAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DoNotOverrideToString_partial-class#UnionConverterFromAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DoNotOverrideToString_partial-class#UnionConverterToAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DoNotOverrideToString_partial-class#UnionConverterToAttribute.g.verified.cs index fae1e4d..28901ff 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DoNotOverrideToString_partial-class#UnionConverterToAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DoNotOverrideToString_partial-class#UnionConverterToAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DoNotOverrideToString_partial-class#UnionTypeAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DoNotOverrideToString_partial-class#UnionTypeAttribute.g.verified.cs index 335ae09..927bc14 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DoNotOverrideToString_partial-class#UnionTypeAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DoNotOverrideToString_partial-class#UnionTypeAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -13,12 +15,24 @@ namespace N.SourceGenerators.UnionTypes internal sealed class UnionTypeAttribute : Attribute { public Type Type { get; } +#if NETCOREAPP3_1_OR_GREATER public string? Alias { get; } +#else + public string Alias { get; } +#endif public int Order { get; } public bool AllowNull { get; set; } +#if NETCOREAPP3_1_OR_GREATER public object? TypeDiscriminator { get; set; } +#else + public object TypeDiscriminator { get; set; } +#endif +#if NETCOREAPP3_1_OR_GREATER public UnionTypeAttribute(Type type, string? alias = null, [CallerLineNumber] int order = 0) +#else + public UnionTypeAttribute(Type type, string alias = null, [CallerLineNumber] int order = 0) +#endif { Type = type; Alias = alias; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DoNotOverrideToString_partial-struct#GenericUnionTypeAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DoNotOverrideToString_partial-struct#GenericUnionTypeAttribute.g.verified.cs index 9930562..17a28f9 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DoNotOverrideToString_partial-struct#GenericUnionTypeAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DoNotOverrideToString_partial-struct#GenericUnionTypeAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -12,8 +14,14 @@ namespace N.SourceGenerators.UnionTypes [AttributeUsage(AttributeTargets.GenericParameter, Inherited = false, AllowMultiple = false)] internal sealed class GenericUnionTypeAttribute : Attribute { +#if NETCOREAPP3_1_OR_GREATER public string? Alias { get; set; } public bool AllowNull { get; set; } public object? TypeDiscriminator { get; set; } +#else + public string Alias { get; set; } + public bool AllowNull { get; set; } + public object TypeDiscriminator { get; set; } +#endif } } \ No newline at end of file diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DoNotOverrideToString_partial-struct#JsonPolymorphicUnionAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DoNotOverrideToString_partial-struct#JsonPolymorphicUnionAttribute.g.verified.cs index e6b2d7c..ee781ad 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DoNotOverrideToString_partial-struct#JsonPolymorphicUnionAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DoNotOverrideToString_partial-struct#JsonPolymorphicUnionAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -12,6 +14,10 @@ namespace N.SourceGenerators.UnionTypes [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] internal sealed class JsonPolymorphicUnionAttribute : Attribute { +#if NETCOREAPP3_1_OR_GREATER public string? TypeDiscriminatorPropertyName { get; set; } +#else + public string TypeDiscriminatorPropertyName { get; set; } +#endif } } \ No newline at end of file diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DoNotOverrideToString_partial-struct#UnionConverterAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DoNotOverrideToString_partial-struct#UnionConverterAttribute.g.verified.cs index 3e6fd2b..973b6e2 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DoNotOverrideToString_partial-struct#UnionConverterAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DoNotOverrideToString_partial-struct#UnionConverterAttribute.g.verified.cs @@ -1,5 +1,7 @@ //HintName: UnionConverterAttribute.g.cs +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -10,9 +12,17 @@ sealed class UnionConverterAttribute : Attribute { public Type FromType { get; } public Type ToType { get; } +#if NETCOREAPP3_1_OR_GREATER public string? MethodName { get; } +#else + public string MethodName { get; } +#endif +#if NETCOREAPP3_1_OR_GREATER public UnionConverterAttribute(Type fromType, Type toType, string? methodName = null) +#else + public UnionConverterAttribute(Type fromType, Type toType, string methodName = null) +#endif { FromType = fromType; ToType = toType; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DoNotOverrideToString_partial-struct#UnionConverterFromAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DoNotOverrideToString_partial-struct#UnionConverterFromAttribute.g.verified.cs index d740ef3..222e936 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DoNotOverrideToString_partial-struct#UnionConverterFromAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DoNotOverrideToString_partial-struct#UnionConverterFromAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DoNotOverrideToString_partial-struct#UnionConverterToAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DoNotOverrideToString_partial-struct#UnionConverterToAttribute.g.verified.cs index fae1e4d..28901ff 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DoNotOverrideToString_partial-struct#UnionConverterToAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DoNotOverrideToString_partial-struct#UnionConverterToAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DoNotOverrideToString_partial-struct#UnionTypeAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DoNotOverrideToString_partial-struct#UnionTypeAttribute.g.verified.cs index 335ae09..927bc14 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DoNotOverrideToString_partial-struct#UnionTypeAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DoNotOverrideToString_partial-struct#UnionTypeAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -13,12 +15,24 @@ namespace N.SourceGenerators.UnionTypes internal sealed class UnionTypeAttribute : Attribute { public Type Type { get; } +#if NETCOREAPP3_1_OR_GREATER public string? Alias { get; } +#else + public string Alias { get; } +#endif public int Order { get; } public bool AllowNull { get; set; } +#if NETCOREAPP3_1_OR_GREATER public object? TypeDiscriminator { get; set; } +#else + public object TypeDiscriminator { get; set; } +#endif +#if NETCOREAPP3_1_OR_GREATER public UnionTypeAttribute(Type type, string? alias = null, [CallerLineNumber] int order = 0) +#else + public UnionTypeAttribute(Type type, string alias = null, [CallerLineNumber] int order = 0) +#endif { Type = type; Alias = alias; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DoNotOverrideToString_readonly-partial-struct#GenericUnionTypeAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DoNotOverrideToString_readonly-partial-struct#GenericUnionTypeAttribute.g.verified.cs index 9930562..17a28f9 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DoNotOverrideToString_readonly-partial-struct#GenericUnionTypeAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DoNotOverrideToString_readonly-partial-struct#GenericUnionTypeAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -12,8 +14,14 @@ namespace N.SourceGenerators.UnionTypes [AttributeUsage(AttributeTargets.GenericParameter, Inherited = false, AllowMultiple = false)] internal sealed class GenericUnionTypeAttribute : Attribute { +#if NETCOREAPP3_1_OR_GREATER public string? Alias { get; set; } public bool AllowNull { get; set; } public object? TypeDiscriminator { get; set; } +#else + public string Alias { get; set; } + public bool AllowNull { get; set; } + public object TypeDiscriminator { get; set; } +#endif } } \ No newline at end of file diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DoNotOverrideToString_readonly-partial-struct#JsonPolymorphicUnionAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DoNotOverrideToString_readonly-partial-struct#JsonPolymorphicUnionAttribute.g.verified.cs index e6b2d7c..ee781ad 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DoNotOverrideToString_readonly-partial-struct#JsonPolymorphicUnionAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DoNotOverrideToString_readonly-partial-struct#JsonPolymorphicUnionAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -12,6 +14,10 @@ namespace N.SourceGenerators.UnionTypes [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] internal sealed class JsonPolymorphicUnionAttribute : Attribute { +#if NETCOREAPP3_1_OR_GREATER public string? TypeDiscriminatorPropertyName { get; set; } +#else + public string TypeDiscriminatorPropertyName { get; set; } +#endif } } \ No newline at end of file diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DoNotOverrideToString_readonly-partial-struct#UnionConverterAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DoNotOverrideToString_readonly-partial-struct#UnionConverterAttribute.g.verified.cs index 3e6fd2b..973b6e2 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DoNotOverrideToString_readonly-partial-struct#UnionConverterAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DoNotOverrideToString_readonly-partial-struct#UnionConverterAttribute.g.verified.cs @@ -1,5 +1,7 @@ //HintName: UnionConverterAttribute.g.cs +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -10,9 +12,17 @@ sealed class UnionConverterAttribute : Attribute { public Type FromType { get; } public Type ToType { get; } +#if NETCOREAPP3_1_OR_GREATER public string? MethodName { get; } +#else + public string MethodName { get; } +#endif +#if NETCOREAPP3_1_OR_GREATER public UnionConverterAttribute(Type fromType, Type toType, string? methodName = null) +#else + public UnionConverterAttribute(Type fromType, Type toType, string methodName = null) +#endif { FromType = fromType; ToType = toType; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DoNotOverrideToString_readonly-partial-struct#UnionConverterFromAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DoNotOverrideToString_readonly-partial-struct#UnionConverterFromAttribute.g.verified.cs index d740ef3..222e936 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DoNotOverrideToString_readonly-partial-struct#UnionConverterFromAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DoNotOverrideToString_readonly-partial-struct#UnionConverterFromAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DoNotOverrideToString_readonly-partial-struct#UnionConverterToAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DoNotOverrideToString_readonly-partial-struct#UnionConverterToAttribute.g.verified.cs index fae1e4d..28901ff 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DoNotOverrideToString_readonly-partial-struct#UnionConverterToAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DoNotOverrideToString_readonly-partial-struct#UnionConverterToAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DoNotOverrideToString_readonly-partial-struct#UnionTypeAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DoNotOverrideToString_readonly-partial-struct#UnionTypeAttribute.g.verified.cs index 335ae09..927bc14 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DoNotOverrideToString_readonly-partial-struct#UnionTypeAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.DoNotOverrideToString_readonly-partial-struct#UnionTypeAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -13,12 +15,24 @@ namespace N.SourceGenerators.UnionTypes internal sealed class UnionTypeAttribute : Attribute { public Type Type { get; } +#if NETCOREAPP3_1_OR_GREATER public string? Alias { get; } +#else + public string Alias { get; } +#endif public int Order { get; } public bool AllowNull { get; set; } +#if NETCOREAPP3_1_OR_GREATER public object? TypeDiscriminator { get; set; } +#else + public object TypeDiscriminator { get; set; } +#endif +#if NETCOREAPP3_1_OR_GREATER public UnionTypeAttribute(Type type, string? alias = null, [CallerLineNumber] int order = 0) +#else + public UnionTypeAttribute(Type type, string alias = null, [CallerLineNumber] int order = 0) +#endif { Type = type; Alias = alias; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.ExplicitStructLayout#GenericUnionTypeAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.ExplicitStructLayout#GenericUnionTypeAttribute.g.verified.cs index 9930562..17a28f9 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.ExplicitStructLayout#GenericUnionTypeAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.ExplicitStructLayout#GenericUnionTypeAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -12,8 +14,14 @@ namespace N.SourceGenerators.UnionTypes [AttributeUsage(AttributeTargets.GenericParameter, Inherited = false, AllowMultiple = false)] internal sealed class GenericUnionTypeAttribute : Attribute { +#if NETCOREAPP3_1_OR_GREATER public string? Alias { get; set; } public bool AllowNull { get; set; } public object? TypeDiscriminator { get; set; } +#else + public string Alias { get; set; } + public bool AllowNull { get; set; } + public object TypeDiscriminator { get; set; } +#endif } } \ No newline at end of file diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.ExplicitStructLayout#JsonPolymorphicUnionAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.ExplicitStructLayout#JsonPolymorphicUnionAttribute.g.verified.cs index e6b2d7c..ee781ad 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.ExplicitStructLayout#JsonPolymorphicUnionAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.ExplicitStructLayout#JsonPolymorphicUnionAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -12,6 +14,10 @@ namespace N.SourceGenerators.UnionTypes [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] internal sealed class JsonPolymorphicUnionAttribute : Attribute { +#if NETCOREAPP3_1_OR_GREATER public string? TypeDiscriminatorPropertyName { get; set; } +#else + public string TypeDiscriminatorPropertyName { get; set; } +#endif } } \ No newline at end of file diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.ExplicitStructLayout#UnionConverterAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.ExplicitStructLayout#UnionConverterAttribute.g.verified.cs index 3e6fd2b..973b6e2 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.ExplicitStructLayout#UnionConverterAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.ExplicitStructLayout#UnionConverterAttribute.g.verified.cs @@ -1,5 +1,7 @@ //HintName: UnionConverterAttribute.g.cs +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -10,9 +12,17 @@ sealed class UnionConverterAttribute : Attribute { public Type FromType { get; } public Type ToType { get; } +#if NETCOREAPP3_1_OR_GREATER public string? MethodName { get; } +#else + public string MethodName { get; } +#endif +#if NETCOREAPP3_1_OR_GREATER public UnionConverterAttribute(Type fromType, Type toType, string? methodName = null) +#else + public UnionConverterAttribute(Type fromType, Type toType, string methodName = null) +#endif { FromType = fromType; ToType = toType; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.ExplicitStructLayout#UnionConverterFromAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.ExplicitStructLayout#UnionConverterFromAttribute.g.verified.cs index d740ef3..222e936 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.ExplicitStructLayout#UnionConverterFromAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.ExplicitStructLayout#UnionConverterFromAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.ExplicitStructLayout#UnionConverterToAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.ExplicitStructLayout#UnionConverterToAttribute.g.verified.cs index fae1e4d..28901ff 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.ExplicitStructLayout#UnionConverterToAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.ExplicitStructLayout#UnionConverterToAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.ExplicitStructLayout#UnionTypeAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.ExplicitStructLayout#UnionTypeAttribute.g.verified.cs index 335ae09..927bc14 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.ExplicitStructLayout#UnionTypeAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.ExplicitStructLayout#UnionTypeAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -13,12 +15,24 @@ namespace N.SourceGenerators.UnionTypes internal sealed class UnionTypeAttribute : Attribute { public Type Type { get; } +#if NETCOREAPP3_1_OR_GREATER public string? Alias { get; } +#else + public string Alias { get; } +#endif public int Order { get; } public bool AllowNull { get; set; } +#if NETCOREAPP3_1_OR_GREATER public object? TypeDiscriminator { get; set; } +#else + public object TypeDiscriminator { get; set; } +#endif +#if NETCOREAPP3_1_OR_GREATER public UnionTypeAttribute(Type type, string? alias = null, [CallerLineNumber] int order = 0) +#else + public UnionTypeAttribute(Type type, string alias = null, [CallerLineNumber] int order = 0) +#endif { Type = type; Alias = alias; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithNamespace_partial-class#GenericUnionTypeAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithNamespace_partial-class#GenericUnionTypeAttribute.g.verified.cs index 9930562..17a28f9 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithNamespace_partial-class#GenericUnionTypeAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithNamespace_partial-class#GenericUnionTypeAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -12,8 +14,14 @@ namespace N.SourceGenerators.UnionTypes [AttributeUsage(AttributeTargets.GenericParameter, Inherited = false, AllowMultiple = false)] internal sealed class GenericUnionTypeAttribute : Attribute { +#if NETCOREAPP3_1_OR_GREATER public string? Alias { get; set; } public bool AllowNull { get; set; } public object? TypeDiscriminator { get; set; } +#else + public string Alias { get; set; } + public bool AllowNull { get; set; } + public object TypeDiscriminator { get; set; } +#endif } } \ No newline at end of file diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithNamespace_partial-class#JsonPolymorphicUnionAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithNamespace_partial-class#JsonPolymorphicUnionAttribute.g.verified.cs index e6b2d7c..ee781ad 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithNamespace_partial-class#JsonPolymorphicUnionAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithNamespace_partial-class#JsonPolymorphicUnionAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -12,6 +14,10 @@ namespace N.SourceGenerators.UnionTypes [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] internal sealed class JsonPolymorphicUnionAttribute : Attribute { +#if NETCOREAPP3_1_OR_GREATER public string? TypeDiscriminatorPropertyName { get; set; } +#else + public string TypeDiscriminatorPropertyName { get; set; } +#endif } } \ No newline at end of file diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithNamespace_partial-class#UnionConverterAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithNamespace_partial-class#UnionConverterAttribute.g.verified.cs index 3e6fd2b..973b6e2 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithNamespace_partial-class#UnionConverterAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithNamespace_partial-class#UnionConverterAttribute.g.verified.cs @@ -1,5 +1,7 @@ //HintName: UnionConverterAttribute.g.cs +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -10,9 +12,17 @@ sealed class UnionConverterAttribute : Attribute { public Type FromType { get; } public Type ToType { get; } +#if NETCOREAPP3_1_OR_GREATER public string? MethodName { get; } +#else + public string MethodName { get; } +#endif +#if NETCOREAPP3_1_OR_GREATER public UnionConverterAttribute(Type fromType, Type toType, string? methodName = null) +#else + public UnionConverterAttribute(Type fromType, Type toType, string methodName = null) +#endif { FromType = fromType; ToType = toType; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithNamespace_partial-class#UnionConverterFromAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithNamespace_partial-class#UnionConverterFromAttribute.g.verified.cs index d740ef3..222e936 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithNamespace_partial-class#UnionConverterFromAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithNamespace_partial-class#UnionConverterFromAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithNamespace_partial-class#UnionConverterToAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithNamespace_partial-class#UnionConverterToAttribute.g.verified.cs index fae1e4d..28901ff 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithNamespace_partial-class#UnionConverterToAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithNamespace_partial-class#UnionConverterToAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithNamespace_partial-class#UnionTypeAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithNamespace_partial-class#UnionTypeAttribute.g.verified.cs index 335ae09..927bc14 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithNamespace_partial-class#UnionTypeAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithNamespace_partial-class#UnionTypeAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -13,12 +15,24 @@ namespace N.SourceGenerators.UnionTypes internal sealed class UnionTypeAttribute : Attribute { public Type Type { get; } +#if NETCOREAPP3_1_OR_GREATER public string? Alias { get; } +#else + public string Alias { get; } +#endif public int Order { get; } public bool AllowNull { get; set; } +#if NETCOREAPP3_1_OR_GREATER public object? TypeDiscriminator { get; set; } +#else + public object TypeDiscriminator { get; set; } +#endif +#if NETCOREAPP3_1_OR_GREATER public UnionTypeAttribute(Type type, string? alias = null, [CallerLineNumber] int order = 0) +#else + public UnionTypeAttribute(Type type, string alias = null, [CallerLineNumber] int order = 0) +#endif { Type = type; Alias = alias; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithNamespace_partial-struct#GenericUnionTypeAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithNamespace_partial-struct#GenericUnionTypeAttribute.g.verified.cs index 9930562..17a28f9 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithNamespace_partial-struct#GenericUnionTypeAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithNamespace_partial-struct#GenericUnionTypeAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -12,8 +14,14 @@ namespace N.SourceGenerators.UnionTypes [AttributeUsage(AttributeTargets.GenericParameter, Inherited = false, AllowMultiple = false)] internal sealed class GenericUnionTypeAttribute : Attribute { +#if NETCOREAPP3_1_OR_GREATER public string? Alias { get; set; } public bool AllowNull { get; set; } public object? TypeDiscriminator { get; set; } +#else + public string Alias { get; set; } + public bool AllowNull { get; set; } + public object TypeDiscriminator { get; set; } +#endif } } \ No newline at end of file diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithNamespace_partial-struct#JsonPolymorphicUnionAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithNamespace_partial-struct#JsonPolymorphicUnionAttribute.g.verified.cs index e6b2d7c..ee781ad 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithNamespace_partial-struct#JsonPolymorphicUnionAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithNamespace_partial-struct#JsonPolymorphicUnionAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -12,6 +14,10 @@ namespace N.SourceGenerators.UnionTypes [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] internal sealed class JsonPolymorphicUnionAttribute : Attribute { +#if NETCOREAPP3_1_OR_GREATER public string? TypeDiscriminatorPropertyName { get; set; } +#else + public string TypeDiscriminatorPropertyName { get; set; } +#endif } } \ No newline at end of file diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithNamespace_partial-struct#UnionConverterAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithNamespace_partial-struct#UnionConverterAttribute.g.verified.cs index 3e6fd2b..973b6e2 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithNamespace_partial-struct#UnionConverterAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithNamespace_partial-struct#UnionConverterAttribute.g.verified.cs @@ -1,5 +1,7 @@ //HintName: UnionConverterAttribute.g.cs +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -10,9 +12,17 @@ sealed class UnionConverterAttribute : Attribute { public Type FromType { get; } public Type ToType { get; } +#if NETCOREAPP3_1_OR_GREATER public string? MethodName { get; } +#else + public string MethodName { get; } +#endif +#if NETCOREAPP3_1_OR_GREATER public UnionConverterAttribute(Type fromType, Type toType, string? methodName = null) +#else + public UnionConverterAttribute(Type fromType, Type toType, string methodName = null) +#endif { FromType = fromType; ToType = toType; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithNamespace_partial-struct#UnionConverterFromAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithNamespace_partial-struct#UnionConverterFromAttribute.g.verified.cs index d740ef3..222e936 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithNamespace_partial-struct#UnionConverterFromAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithNamespace_partial-struct#UnionConverterFromAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithNamespace_partial-struct#UnionConverterToAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithNamespace_partial-struct#UnionConverterToAttribute.g.verified.cs index fae1e4d..28901ff 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithNamespace_partial-struct#UnionConverterToAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithNamespace_partial-struct#UnionConverterToAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithNamespace_partial-struct#UnionTypeAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithNamespace_partial-struct#UnionTypeAttribute.g.verified.cs index 335ae09..927bc14 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithNamespace_partial-struct#UnionTypeAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithNamespace_partial-struct#UnionTypeAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -13,12 +15,24 @@ namespace N.SourceGenerators.UnionTypes internal sealed class UnionTypeAttribute : Attribute { public Type Type { get; } +#if NETCOREAPP3_1_OR_GREATER public string? Alias { get; } +#else + public string Alias { get; } +#endif public int Order { get; } public bool AllowNull { get; set; } +#if NETCOREAPP3_1_OR_GREATER public object? TypeDiscriminator { get; set; } +#else + public object TypeDiscriminator { get; set; } +#endif +#if NETCOREAPP3_1_OR_GREATER public UnionTypeAttribute(Type type, string? alias = null, [CallerLineNumber] int order = 0) +#else + public UnionTypeAttribute(Type type, string alias = null, [CallerLineNumber] int order = 0) +#endif { Type = type; Alias = alias; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithNamespace_readonly-partial-struct#GenericUnionTypeAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithNamespace_readonly-partial-struct#GenericUnionTypeAttribute.g.verified.cs index 9930562..17a28f9 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithNamespace_readonly-partial-struct#GenericUnionTypeAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithNamespace_readonly-partial-struct#GenericUnionTypeAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -12,8 +14,14 @@ namespace N.SourceGenerators.UnionTypes [AttributeUsage(AttributeTargets.GenericParameter, Inherited = false, AllowMultiple = false)] internal sealed class GenericUnionTypeAttribute : Attribute { +#if NETCOREAPP3_1_OR_GREATER public string? Alias { get; set; } public bool AllowNull { get; set; } public object? TypeDiscriminator { get; set; } +#else + public string Alias { get; set; } + public bool AllowNull { get; set; } + public object TypeDiscriminator { get; set; } +#endif } } \ No newline at end of file diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithNamespace_readonly-partial-struct#JsonPolymorphicUnionAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithNamespace_readonly-partial-struct#JsonPolymorphicUnionAttribute.g.verified.cs index e6b2d7c..ee781ad 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithNamespace_readonly-partial-struct#JsonPolymorphicUnionAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithNamespace_readonly-partial-struct#JsonPolymorphicUnionAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -12,6 +14,10 @@ namespace N.SourceGenerators.UnionTypes [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] internal sealed class JsonPolymorphicUnionAttribute : Attribute { +#if NETCOREAPP3_1_OR_GREATER public string? TypeDiscriminatorPropertyName { get; set; } +#else + public string TypeDiscriminatorPropertyName { get; set; } +#endif } } \ No newline at end of file diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithNamespace_readonly-partial-struct#UnionConverterAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithNamespace_readonly-partial-struct#UnionConverterAttribute.g.verified.cs index 3e6fd2b..973b6e2 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithNamespace_readonly-partial-struct#UnionConverterAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithNamespace_readonly-partial-struct#UnionConverterAttribute.g.verified.cs @@ -1,5 +1,7 @@ //HintName: UnionConverterAttribute.g.cs +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -10,9 +12,17 @@ sealed class UnionConverterAttribute : Attribute { public Type FromType { get; } public Type ToType { get; } +#if NETCOREAPP3_1_OR_GREATER public string? MethodName { get; } +#else + public string MethodName { get; } +#endif +#if NETCOREAPP3_1_OR_GREATER public UnionConverterAttribute(Type fromType, Type toType, string? methodName = null) +#else + public UnionConverterAttribute(Type fromType, Type toType, string methodName = null) +#endif { FromType = fromType; ToType = toType; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithNamespace_readonly-partial-struct#UnionConverterFromAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithNamespace_readonly-partial-struct#UnionConverterFromAttribute.g.verified.cs index d740ef3..222e936 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithNamespace_readonly-partial-struct#UnionConverterFromAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithNamespace_readonly-partial-struct#UnionConverterFromAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithNamespace_readonly-partial-struct#UnionConverterToAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithNamespace_readonly-partial-struct#UnionConverterToAttribute.g.verified.cs index fae1e4d..28901ff 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithNamespace_readonly-partial-struct#UnionConverterToAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithNamespace_readonly-partial-struct#UnionConverterToAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithNamespace_readonly-partial-struct#UnionTypeAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithNamespace_readonly-partial-struct#UnionTypeAttribute.g.verified.cs index 335ae09..927bc14 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithNamespace_readonly-partial-struct#UnionTypeAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithNamespace_readonly-partial-struct#UnionTypeAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -13,12 +15,24 @@ namespace N.SourceGenerators.UnionTypes internal sealed class UnionTypeAttribute : Attribute { public Type Type { get; } +#if NETCOREAPP3_1_OR_GREATER public string? Alias { get; } +#else + public string Alias { get; } +#endif public int Order { get; } public bool AllowNull { get; set; } +#if NETCOREAPP3_1_OR_GREATER public object? TypeDiscriminator { get; set; } +#else + public object TypeDiscriminator { get; set; } +#endif +#if NETCOREAPP3_1_OR_GREATER public UnionTypeAttribute(Type type, string? alias = null, [CallerLineNumber] int order = 0) +#else + public UnionTypeAttribute(Type type, string alias = null, [CallerLineNumber] int order = 0) +#endif { Type = type; Alias = alias; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithoutNamespace_partial-class#GenericUnionTypeAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithoutNamespace_partial-class#GenericUnionTypeAttribute.g.verified.cs index 9930562..17a28f9 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithoutNamespace_partial-class#GenericUnionTypeAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithoutNamespace_partial-class#GenericUnionTypeAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -12,8 +14,14 @@ namespace N.SourceGenerators.UnionTypes [AttributeUsage(AttributeTargets.GenericParameter, Inherited = false, AllowMultiple = false)] internal sealed class GenericUnionTypeAttribute : Attribute { +#if NETCOREAPP3_1_OR_GREATER public string? Alias { get; set; } public bool AllowNull { get; set; } public object? TypeDiscriminator { get; set; } +#else + public string Alias { get; set; } + public bool AllowNull { get; set; } + public object TypeDiscriminator { get; set; } +#endif } } \ No newline at end of file diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithoutNamespace_partial-class#JsonPolymorphicUnionAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithoutNamespace_partial-class#JsonPolymorphicUnionAttribute.g.verified.cs index e6b2d7c..ee781ad 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithoutNamespace_partial-class#JsonPolymorphicUnionAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithoutNamespace_partial-class#JsonPolymorphicUnionAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -12,6 +14,10 @@ namespace N.SourceGenerators.UnionTypes [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] internal sealed class JsonPolymorphicUnionAttribute : Attribute { +#if NETCOREAPP3_1_OR_GREATER public string? TypeDiscriminatorPropertyName { get; set; } +#else + public string TypeDiscriminatorPropertyName { get; set; } +#endif } } \ No newline at end of file diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithoutNamespace_partial-class#UnionConverterAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithoutNamespace_partial-class#UnionConverterAttribute.g.verified.cs index 3e6fd2b..973b6e2 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithoutNamespace_partial-class#UnionConverterAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithoutNamespace_partial-class#UnionConverterAttribute.g.verified.cs @@ -1,5 +1,7 @@ //HintName: UnionConverterAttribute.g.cs +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -10,9 +12,17 @@ sealed class UnionConverterAttribute : Attribute { public Type FromType { get; } public Type ToType { get; } +#if NETCOREAPP3_1_OR_GREATER public string? MethodName { get; } +#else + public string MethodName { get; } +#endif +#if NETCOREAPP3_1_OR_GREATER public UnionConverterAttribute(Type fromType, Type toType, string? methodName = null) +#else + public UnionConverterAttribute(Type fromType, Type toType, string methodName = null) +#endif { FromType = fromType; ToType = toType; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithoutNamespace_partial-class#UnionConverterFromAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithoutNamespace_partial-class#UnionConverterFromAttribute.g.verified.cs index d740ef3..222e936 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithoutNamespace_partial-class#UnionConverterFromAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithoutNamespace_partial-class#UnionConverterFromAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithoutNamespace_partial-class#UnionConverterToAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithoutNamespace_partial-class#UnionConverterToAttribute.g.verified.cs index fae1e4d..28901ff 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithoutNamespace_partial-class#UnionConverterToAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithoutNamespace_partial-class#UnionConverterToAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithoutNamespace_partial-class#UnionTypeAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithoutNamespace_partial-class#UnionTypeAttribute.g.verified.cs index 335ae09..927bc14 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithoutNamespace_partial-class#UnionTypeAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithoutNamespace_partial-class#UnionTypeAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -13,12 +15,24 @@ namespace N.SourceGenerators.UnionTypes internal sealed class UnionTypeAttribute : Attribute { public Type Type { get; } +#if NETCOREAPP3_1_OR_GREATER public string? Alias { get; } +#else + public string Alias { get; } +#endif public int Order { get; } public bool AllowNull { get; set; } +#if NETCOREAPP3_1_OR_GREATER public object? TypeDiscriminator { get; set; } +#else + public object TypeDiscriminator { get; set; } +#endif +#if NETCOREAPP3_1_OR_GREATER public UnionTypeAttribute(Type type, string? alias = null, [CallerLineNumber] int order = 0) +#else + public UnionTypeAttribute(Type type, string alias = null, [CallerLineNumber] int order = 0) +#endif { Type = type; Alias = alias; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithoutNamespace_partial-struct#GenericUnionTypeAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithoutNamespace_partial-struct#GenericUnionTypeAttribute.g.verified.cs index 9930562..17a28f9 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithoutNamespace_partial-struct#GenericUnionTypeAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithoutNamespace_partial-struct#GenericUnionTypeAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -12,8 +14,14 @@ namespace N.SourceGenerators.UnionTypes [AttributeUsage(AttributeTargets.GenericParameter, Inherited = false, AllowMultiple = false)] internal sealed class GenericUnionTypeAttribute : Attribute { +#if NETCOREAPP3_1_OR_GREATER public string? Alias { get; set; } public bool AllowNull { get; set; } public object? TypeDiscriminator { get; set; } +#else + public string Alias { get; set; } + public bool AllowNull { get; set; } + public object TypeDiscriminator { get; set; } +#endif } } \ No newline at end of file diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithoutNamespace_partial-struct#JsonPolymorphicUnionAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithoutNamespace_partial-struct#JsonPolymorphicUnionAttribute.g.verified.cs index e6b2d7c..ee781ad 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithoutNamespace_partial-struct#JsonPolymorphicUnionAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithoutNamespace_partial-struct#JsonPolymorphicUnionAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -12,6 +14,10 @@ namespace N.SourceGenerators.UnionTypes [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] internal sealed class JsonPolymorphicUnionAttribute : Attribute { +#if NETCOREAPP3_1_OR_GREATER public string? TypeDiscriminatorPropertyName { get; set; } +#else + public string TypeDiscriminatorPropertyName { get; set; } +#endif } } \ No newline at end of file diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithoutNamespace_partial-struct#UnionConverterAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithoutNamespace_partial-struct#UnionConverterAttribute.g.verified.cs index 3e6fd2b..973b6e2 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithoutNamespace_partial-struct#UnionConverterAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithoutNamespace_partial-struct#UnionConverterAttribute.g.verified.cs @@ -1,5 +1,7 @@ //HintName: UnionConverterAttribute.g.cs +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -10,9 +12,17 @@ sealed class UnionConverterAttribute : Attribute { public Type FromType { get; } public Type ToType { get; } +#if NETCOREAPP3_1_OR_GREATER public string? MethodName { get; } +#else + public string MethodName { get; } +#endif +#if NETCOREAPP3_1_OR_GREATER public UnionConverterAttribute(Type fromType, Type toType, string? methodName = null) +#else + public UnionConverterAttribute(Type fromType, Type toType, string methodName = null) +#endif { FromType = fromType; ToType = toType; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithoutNamespace_partial-struct#UnionConverterFromAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithoutNamespace_partial-struct#UnionConverterFromAttribute.g.verified.cs index d740ef3..222e936 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithoutNamespace_partial-struct#UnionConverterFromAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithoutNamespace_partial-struct#UnionConverterFromAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithoutNamespace_partial-struct#UnionConverterToAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithoutNamespace_partial-struct#UnionConverterToAttribute.g.verified.cs index fae1e4d..28901ff 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithoutNamespace_partial-struct#UnionConverterToAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithoutNamespace_partial-struct#UnionConverterToAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithoutNamespace_partial-struct#UnionTypeAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithoutNamespace_partial-struct#UnionTypeAttribute.g.verified.cs index 335ae09..927bc14 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithoutNamespace_partial-struct#UnionTypeAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithoutNamespace_partial-struct#UnionTypeAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -13,12 +15,24 @@ namespace N.SourceGenerators.UnionTypes internal sealed class UnionTypeAttribute : Attribute { public Type Type { get; } +#if NETCOREAPP3_1_OR_GREATER public string? Alias { get; } +#else + public string Alias { get; } +#endif public int Order { get; } public bool AllowNull { get; set; } +#if NETCOREAPP3_1_OR_GREATER public object? TypeDiscriminator { get; set; } +#else + public object TypeDiscriminator { get; set; } +#endif +#if NETCOREAPP3_1_OR_GREATER public UnionTypeAttribute(Type type, string? alias = null, [CallerLineNumber] int order = 0) +#else + public UnionTypeAttribute(Type type, string alias = null, [CallerLineNumber] int order = 0) +#endif { Type = type; Alias = alias; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithoutNamespace_readonly-partial-struct#GenericUnionTypeAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithoutNamespace_readonly-partial-struct#GenericUnionTypeAttribute.g.verified.cs index 9930562..17a28f9 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithoutNamespace_readonly-partial-struct#GenericUnionTypeAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithoutNamespace_readonly-partial-struct#GenericUnionTypeAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -12,8 +14,14 @@ namespace N.SourceGenerators.UnionTypes [AttributeUsage(AttributeTargets.GenericParameter, Inherited = false, AllowMultiple = false)] internal sealed class GenericUnionTypeAttribute : Attribute { +#if NETCOREAPP3_1_OR_GREATER public string? Alias { get; set; } public bool AllowNull { get; set; } public object? TypeDiscriminator { get; set; } +#else + public string Alias { get; set; } + public bool AllowNull { get; set; } + public object TypeDiscriminator { get; set; } +#endif } } \ No newline at end of file diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithoutNamespace_readonly-partial-struct#JsonPolymorphicUnionAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithoutNamespace_readonly-partial-struct#JsonPolymorphicUnionAttribute.g.verified.cs index e6b2d7c..ee781ad 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithoutNamespace_readonly-partial-struct#JsonPolymorphicUnionAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithoutNamespace_readonly-partial-struct#JsonPolymorphicUnionAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -12,6 +14,10 @@ namespace N.SourceGenerators.UnionTypes [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] internal sealed class JsonPolymorphicUnionAttribute : Attribute { +#if NETCOREAPP3_1_OR_GREATER public string? TypeDiscriminatorPropertyName { get; set; } +#else + public string TypeDiscriminatorPropertyName { get; set; } +#endif } } \ No newline at end of file diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithoutNamespace_readonly-partial-struct#UnionConverterAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithoutNamespace_readonly-partial-struct#UnionConverterAttribute.g.verified.cs index 3e6fd2b..973b6e2 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithoutNamespace_readonly-partial-struct#UnionConverterAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithoutNamespace_readonly-partial-struct#UnionConverterAttribute.g.verified.cs @@ -1,5 +1,7 @@ //HintName: UnionConverterAttribute.g.cs +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -10,9 +12,17 @@ sealed class UnionConverterAttribute : Attribute { public Type FromType { get; } public Type ToType { get; } +#if NETCOREAPP3_1_OR_GREATER public string? MethodName { get; } +#else + public string MethodName { get; } +#endif +#if NETCOREAPP3_1_OR_GREATER public UnionConverterAttribute(Type fromType, Type toType, string? methodName = null) +#else + public UnionConverterAttribute(Type fromType, Type toType, string methodName = null) +#endif { FromType = fromType; ToType = toType; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithoutNamespace_readonly-partial-struct#UnionConverterFromAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithoutNamespace_readonly-partial-struct#UnionConverterFromAttribute.g.verified.cs index d740ef3..222e936 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithoutNamespace_readonly-partial-struct#UnionConverterFromAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithoutNamespace_readonly-partial-struct#UnionConverterFromAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithoutNamespace_readonly-partial-struct#UnionConverterToAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithoutNamespace_readonly-partial-struct#UnionConverterToAttribute.g.verified.cs index fae1e4d..28901ff 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithoutNamespace_readonly-partial-struct#UnionConverterToAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithoutNamespace_readonly-partial-struct#UnionConverterToAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithoutNamespace_readonly-partial-struct#UnionTypeAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithoutNamespace_readonly-partial-struct#UnionTypeAttribute.g.verified.cs index 335ae09..927bc14 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithoutNamespace_readonly-partial-struct#UnionTypeAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.WithoutNamespace_readonly-partial-struct#UnionTypeAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -13,12 +15,24 @@ namespace N.SourceGenerators.UnionTypes internal sealed class UnionTypeAttribute : Attribute { public Type Type { get; } +#if NETCOREAPP3_1_OR_GREATER public string? Alias { get; } +#else + public string Alias { get; } +#endif public int Order { get; } public bool AllowNull { get; set; } +#if NETCOREAPP3_1_OR_GREATER public object? TypeDiscriminator { get; set; } +#else + public object TypeDiscriminator { get; set; } +#endif +#if NETCOREAPP3_1_OR_GREATER public UnionTypeAttribute(Type type, string? alias = null, [CallerLineNumber] int order = 0) +#else + public UnionTypeAttribute(Type type, string alias = null, [CallerLineNumber] int order = 0) +#endif { Type = type; Alias = alias; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GenericUnionTests.OnlyGenericTypes#GenericUnionTypeAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GenericUnionTests.OnlyGenericTypes#GenericUnionTypeAttribute.g.verified.cs index 9930562..17a28f9 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GenericUnionTests.OnlyGenericTypes#GenericUnionTypeAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GenericUnionTests.OnlyGenericTypes#GenericUnionTypeAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -12,8 +14,14 @@ namespace N.SourceGenerators.UnionTypes [AttributeUsage(AttributeTargets.GenericParameter, Inherited = false, AllowMultiple = false)] internal sealed class GenericUnionTypeAttribute : Attribute { +#if NETCOREAPP3_1_OR_GREATER public string? Alias { get; set; } public bool AllowNull { get; set; } public object? TypeDiscriminator { get; set; } +#else + public string Alias { get; set; } + public bool AllowNull { get; set; } + public object TypeDiscriminator { get; set; } +#endif } } \ No newline at end of file diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GenericUnionTests.OnlyGenericTypes#JsonPolymorphicUnionAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GenericUnionTests.OnlyGenericTypes#JsonPolymorphicUnionAttribute.g.verified.cs index e6b2d7c..ee781ad 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GenericUnionTests.OnlyGenericTypes#JsonPolymorphicUnionAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GenericUnionTests.OnlyGenericTypes#JsonPolymorphicUnionAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -12,6 +14,10 @@ namespace N.SourceGenerators.UnionTypes [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] internal sealed class JsonPolymorphicUnionAttribute : Attribute { +#if NETCOREAPP3_1_OR_GREATER public string? TypeDiscriminatorPropertyName { get; set; } +#else + public string TypeDiscriminatorPropertyName { get; set; } +#endif } } \ No newline at end of file diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GenericUnionTests.OnlyGenericTypes#UnionConverterAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GenericUnionTests.OnlyGenericTypes#UnionConverterAttribute.g.verified.cs index 3e6fd2b..973b6e2 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GenericUnionTests.OnlyGenericTypes#UnionConverterAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GenericUnionTests.OnlyGenericTypes#UnionConverterAttribute.g.verified.cs @@ -1,5 +1,7 @@ //HintName: UnionConverterAttribute.g.cs +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -10,9 +12,17 @@ sealed class UnionConverterAttribute : Attribute { public Type FromType { get; } public Type ToType { get; } +#if NETCOREAPP3_1_OR_GREATER public string? MethodName { get; } +#else + public string MethodName { get; } +#endif +#if NETCOREAPP3_1_OR_GREATER public UnionConverterAttribute(Type fromType, Type toType, string? methodName = null) +#else + public UnionConverterAttribute(Type fromType, Type toType, string methodName = null) +#endif { FromType = fromType; ToType = toType; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GenericUnionTests.OnlyGenericTypes#UnionConverterFromAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GenericUnionTests.OnlyGenericTypes#UnionConverterFromAttribute.g.verified.cs index d740ef3..222e936 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GenericUnionTests.OnlyGenericTypes#UnionConverterFromAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GenericUnionTests.OnlyGenericTypes#UnionConverterFromAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GenericUnionTests.OnlyGenericTypes#UnionConverterToAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GenericUnionTests.OnlyGenericTypes#UnionConverterToAttribute.g.verified.cs index fae1e4d..28901ff 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GenericUnionTests.OnlyGenericTypes#UnionConverterToAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GenericUnionTests.OnlyGenericTypes#UnionConverterToAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GenericUnionTests.OnlyGenericTypes#UnionTypeAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GenericUnionTests.OnlyGenericTypes#UnionTypeAttribute.g.verified.cs index 335ae09..927bc14 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GenericUnionTests.OnlyGenericTypes#UnionTypeAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GenericUnionTests.OnlyGenericTypes#UnionTypeAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -13,12 +15,24 @@ namespace N.SourceGenerators.UnionTypes internal sealed class UnionTypeAttribute : Attribute { public Type Type { get; } +#if NETCOREAPP3_1_OR_GREATER public string? Alias { get; } +#else + public string Alias { get; } +#endif public int Order { get; } public bool AllowNull { get; set; } +#if NETCOREAPP3_1_OR_GREATER public object? TypeDiscriminator { get; set; } +#else + public object TypeDiscriminator { get; set; } +#endif +#if NETCOREAPP3_1_OR_GREATER public UnionTypeAttribute(Type type, string? alias = null, [CallerLineNumber] int order = 0) +#else + public UnionTypeAttribute(Type type, string alias = null, [CallerLineNumber] int order = 0) +#endif { Type = type; Alias = alias; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GenericUnionTests.WithAlias#GenericUnionTypeAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GenericUnionTests.WithAlias#GenericUnionTypeAttribute.g.verified.cs index 9930562..17a28f9 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GenericUnionTests.WithAlias#GenericUnionTypeAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GenericUnionTests.WithAlias#GenericUnionTypeAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -12,8 +14,14 @@ namespace N.SourceGenerators.UnionTypes [AttributeUsage(AttributeTargets.GenericParameter, Inherited = false, AllowMultiple = false)] internal sealed class GenericUnionTypeAttribute : Attribute { +#if NETCOREAPP3_1_OR_GREATER public string? Alias { get; set; } public bool AllowNull { get; set; } public object? TypeDiscriminator { get; set; } +#else + public string Alias { get; set; } + public bool AllowNull { get; set; } + public object TypeDiscriminator { get; set; } +#endif } } \ No newline at end of file diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GenericUnionTests.WithAlias#JsonPolymorphicUnionAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GenericUnionTests.WithAlias#JsonPolymorphicUnionAttribute.g.verified.cs index e6b2d7c..ee781ad 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GenericUnionTests.WithAlias#JsonPolymorphicUnionAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GenericUnionTests.WithAlias#JsonPolymorphicUnionAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -12,6 +14,10 @@ namespace N.SourceGenerators.UnionTypes [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] internal sealed class JsonPolymorphicUnionAttribute : Attribute { +#if NETCOREAPP3_1_OR_GREATER public string? TypeDiscriminatorPropertyName { get; set; } +#else + public string TypeDiscriminatorPropertyName { get; set; } +#endif } } \ No newline at end of file diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GenericUnionTests.WithAlias#UnionConverterAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GenericUnionTests.WithAlias#UnionConverterAttribute.g.verified.cs index 3e6fd2b..973b6e2 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GenericUnionTests.WithAlias#UnionConverterAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GenericUnionTests.WithAlias#UnionConverterAttribute.g.verified.cs @@ -1,5 +1,7 @@ //HintName: UnionConverterAttribute.g.cs +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -10,9 +12,17 @@ sealed class UnionConverterAttribute : Attribute { public Type FromType { get; } public Type ToType { get; } +#if NETCOREAPP3_1_OR_GREATER public string? MethodName { get; } +#else + public string MethodName { get; } +#endif +#if NETCOREAPP3_1_OR_GREATER public UnionConverterAttribute(Type fromType, Type toType, string? methodName = null) +#else + public UnionConverterAttribute(Type fromType, Type toType, string methodName = null) +#endif { FromType = fromType; ToType = toType; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GenericUnionTests.WithAlias#UnionConverterFromAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GenericUnionTests.WithAlias#UnionConverterFromAttribute.g.verified.cs index d740ef3..222e936 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GenericUnionTests.WithAlias#UnionConverterFromAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GenericUnionTests.WithAlias#UnionConverterFromAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GenericUnionTests.WithAlias#UnionConverterToAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GenericUnionTests.WithAlias#UnionConverterToAttribute.g.verified.cs index fae1e4d..28901ff 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GenericUnionTests.WithAlias#UnionConverterToAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GenericUnionTests.WithAlias#UnionConverterToAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GenericUnionTests.WithAlias#UnionTypeAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GenericUnionTests.WithAlias#UnionTypeAttribute.g.verified.cs index 335ae09..927bc14 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GenericUnionTests.WithAlias#UnionTypeAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GenericUnionTests.WithAlias#UnionTypeAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -13,12 +15,24 @@ namespace N.SourceGenerators.UnionTypes internal sealed class UnionTypeAttribute : Attribute { public Type Type { get; } +#if NETCOREAPP3_1_OR_GREATER public string? Alias { get; } +#else + public string Alias { get; } +#endif public int Order { get; } public bool AllowNull { get; set; } +#if NETCOREAPP3_1_OR_GREATER public object? TypeDiscriminator { get; set; } +#else + public object TypeDiscriminator { get; set; } +#endif +#if NETCOREAPP3_1_OR_GREATER public UnionTypeAttribute(Type type, string? alias = null, [CallerLineNumber] int order = 0) +#else + public UnionTypeAttribute(Type type, string alias = null, [CallerLineNumber] int order = 0) +#endif { Type = type; Alias = alias; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GenericUnionTests.WithCustomUnionType#GenericUnionTypeAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GenericUnionTests.WithCustomUnionType#GenericUnionTypeAttribute.g.verified.cs index 9930562..17a28f9 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GenericUnionTests.WithCustomUnionType#GenericUnionTypeAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GenericUnionTests.WithCustomUnionType#GenericUnionTypeAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -12,8 +14,14 @@ namespace N.SourceGenerators.UnionTypes [AttributeUsage(AttributeTargets.GenericParameter, Inherited = false, AllowMultiple = false)] internal sealed class GenericUnionTypeAttribute : Attribute { +#if NETCOREAPP3_1_OR_GREATER public string? Alias { get; set; } public bool AllowNull { get; set; } public object? TypeDiscriminator { get; set; } +#else + public string Alias { get; set; } + public bool AllowNull { get; set; } + public object TypeDiscriminator { get; set; } +#endif } } \ No newline at end of file diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GenericUnionTests.WithCustomUnionType#JsonPolymorphicUnionAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GenericUnionTests.WithCustomUnionType#JsonPolymorphicUnionAttribute.g.verified.cs index e6b2d7c..ee781ad 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GenericUnionTests.WithCustomUnionType#JsonPolymorphicUnionAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GenericUnionTests.WithCustomUnionType#JsonPolymorphicUnionAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -12,6 +14,10 @@ namespace N.SourceGenerators.UnionTypes [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] internal sealed class JsonPolymorphicUnionAttribute : Attribute { +#if NETCOREAPP3_1_OR_GREATER public string? TypeDiscriminatorPropertyName { get; set; } +#else + public string TypeDiscriminatorPropertyName { get; set; } +#endif } } \ No newline at end of file diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GenericUnionTests.WithCustomUnionType#UnionConverterAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GenericUnionTests.WithCustomUnionType#UnionConverterAttribute.g.verified.cs index 3e6fd2b..973b6e2 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GenericUnionTests.WithCustomUnionType#UnionConverterAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GenericUnionTests.WithCustomUnionType#UnionConverterAttribute.g.verified.cs @@ -1,5 +1,7 @@ //HintName: UnionConverterAttribute.g.cs +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -10,9 +12,17 @@ sealed class UnionConverterAttribute : Attribute { public Type FromType { get; } public Type ToType { get; } +#if NETCOREAPP3_1_OR_GREATER public string? MethodName { get; } +#else + public string MethodName { get; } +#endif +#if NETCOREAPP3_1_OR_GREATER public UnionConverterAttribute(Type fromType, Type toType, string? methodName = null) +#else + public UnionConverterAttribute(Type fromType, Type toType, string methodName = null) +#endif { FromType = fromType; ToType = toType; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GenericUnionTests.WithCustomUnionType#UnionConverterFromAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GenericUnionTests.WithCustomUnionType#UnionConverterFromAttribute.g.verified.cs index d740ef3..222e936 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GenericUnionTests.WithCustomUnionType#UnionConverterFromAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GenericUnionTests.WithCustomUnionType#UnionConverterFromAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GenericUnionTests.WithCustomUnionType#UnionConverterToAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GenericUnionTests.WithCustomUnionType#UnionConverterToAttribute.g.verified.cs index fae1e4d..28901ff 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GenericUnionTests.WithCustomUnionType#UnionConverterToAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GenericUnionTests.WithCustomUnionType#UnionConverterToAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GenericUnionTests.WithCustomUnionType#UnionTypeAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GenericUnionTests.WithCustomUnionType#UnionTypeAttribute.g.verified.cs index 335ae09..927bc14 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GenericUnionTests.WithCustomUnionType#UnionTypeAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GenericUnionTests.WithCustomUnionType#UnionTypeAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -13,12 +15,24 @@ namespace N.SourceGenerators.UnionTypes internal sealed class UnionTypeAttribute : Attribute { public Type Type { get; } +#if NETCOREAPP3_1_OR_GREATER public string? Alias { get; } +#else + public string Alias { get; } +#endif public int Order { get; } public bool AllowNull { get; set; } +#if NETCOREAPP3_1_OR_GREATER public object? TypeDiscriminator { get; set; } +#else + public object TypeDiscriminator { get; set; } +#endif +#if NETCOREAPP3_1_OR_GREATER public UnionTypeAttribute(Type type, string? alias = null, [CallerLineNumber] int order = 0) +#else + public UnionTypeAttribute(Type type, string alias = null, [CallerLineNumber] int order = 0) +#endif { Type = type; Alias = alias; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/JsonTests.ItDoesNotFail#GenericUnionTypeAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/JsonTests.ItDoesNotFail#GenericUnionTypeAttribute.g.verified.cs index 9930562..17a28f9 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/JsonTests.ItDoesNotFail#GenericUnionTypeAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/JsonTests.ItDoesNotFail#GenericUnionTypeAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -12,8 +14,14 @@ namespace N.SourceGenerators.UnionTypes [AttributeUsage(AttributeTargets.GenericParameter, Inherited = false, AllowMultiple = false)] internal sealed class GenericUnionTypeAttribute : Attribute { +#if NETCOREAPP3_1_OR_GREATER public string? Alias { get; set; } public bool AllowNull { get; set; } public object? TypeDiscriminator { get; set; } +#else + public string Alias { get; set; } + public bool AllowNull { get; set; } + public object TypeDiscriminator { get; set; } +#endif } } \ No newline at end of file diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/JsonTests.ItDoesNotFail#JsonPolymorphicUnionAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/JsonTests.ItDoesNotFail#JsonPolymorphicUnionAttribute.g.verified.cs index e6b2d7c..ee781ad 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/JsonTests.ItDoesNotFail#JsonPolymorphicUnionAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/JsonTests.ItDoesNotFail#JsonPolymorphicUnionAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -12,6 +14,10 @@ namespace N.SourceGenerators.UnionTypes [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] internal sealed class JsonPolymorphicUnionAttribute : Attribute { +#if NETCOREAPP3_1_OR_GREATER public string? TypeDiscriminatorPropertyName { get; set; } +#else + public string TypeDiscriminatorPropertyName { get; set; } +#endif } } \ No newline at end of file diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/JsonTests.ItDoesNotFail#UnionConverterAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/JsonTests.ItDoesNotFail#UnionConverterAttribute.g.verified.cs index 3e6fd2b..973b6e2 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/JsonTests.ItDoesNotFail#UnionConverterAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/JsonTests.ItDoesNotFail#UnionConverterAttribute.g.verified.cs @@ -1,5 +1,7 @@ //HintName: UnionConverterAttribute.g.cs +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -10,9 +12,17 @@ sealed class UnionConverterAttribute : Attribute { public Type FromType { get; } public Type ToType { get; } +#if NETCOREAPP3_1_OR_GREATER public string? MethodName { get; } +#else + public string MethodName { get; } +#endif +#if NETCOREAPP3_1_OR_GREATER public UnionConverterAttribute(Type fromType, Type toType, string? methodName = null) +#else + public UnionConverterAttribute(Type fromType, Type toType, string methodName = null) +#endif { FromType = fromType; ToType = toType; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/JsonTests.ItDoesNotFail#UnionConverterFromAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/JsonTests.ItDoesNotFail#UnionConverterFromAttribute.g.verified.cs index d740ef3..222e936 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/JsonTests.ItDoesNotFail#UnionConverterFromAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/JsonTests.ItDoesNotFail#UnionConverterFromAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/JsonTests.ItDoesNotFail#UnionConverterToAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/JsonTests.ItDoesNotFail#UnionConverterToAttribute.g.verified.cs index fae1e4d..28901ff 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/JsonTests.ItDoesNotFail#UnionConverterToAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/JsonTests.ItDoesNotFail#UnionConverterToAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/JsonTests.ItDoesNotFail#UnionTypeAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/JsonTests.ItDoesNotFail#UnionTypeAttribute.g.verified.cs index 335ae09..927bc14 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/JsonTests.ItDoesNotFail#UnionTypeAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/JsonTests.ItDoesNotFail#UnionTypeAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -13,12 +15,24 @@ namespace N.SourceGenerators.UnionTypes internal sealed class UnionTypeAttribute : Attribute { public Type Type { get; } +#if NETCOREAPP3_1_OR_GREATER public string? Alias { get; } +#else + public string Alias { get; } +#endif public int Order { get; } public bool AllowNull { get; set; } +#if NETCOREAPP3_1_OR_GREATER public object? TypeDiscriminator { get; set; } +#else + public object TypeDiscriminator { get; set; } +#endif +#if NETCOREAPP3_1_OR_GREATER public UnionTypeAttribute(Type type, string? alias = null, [CallerLineNumber] int order = 0) +#else + public UnionTypeAttribute(Type type, string alias = null, [CallerLineNumber] int order = 0) +#endif { Type = type; Alias = alias; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/NullableValueTests.UseAllowNullAttribute#GenericUnionTypeAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/NullableValueTests.UseAllowNullAttribute#GenericUnionTypeAttribute.g.verified.cs index 9930562..17a28f9 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/NullableValueTests.UseAllowNullAttribute#GenericUnionTypeAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/NullableValueTests.UseAllowNullAttribute#GenericUnionTypeAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -12,8 +14,14 @@ namespace N.SourceGenerators.UnionTypes [AttributeUsage(AttributeTargets.GenericParameter, Inherited = false, AllowMultiple = false)] internal sealed class GenericUnionTypeAttribute : Attribute { +#if NETCOREAPP3_1_OR_GREATER public string? Alias { get; set; } public bool AllowNull { get; set; } public object? TypeDiscriminator { get; set; } +#else + public string Alias { get; set; } + public bool AllowNull { get; set; } + public object TypeDiscriminator { get; set; } +#endif } } \ No newline at end of file diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/NullableValueTests.UseAllowNullAttribute#JsonPolymorphicUnionAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/NullableValueTests.UseAllowNullAttribute#JsonPolymorphicUnionAttribute.g.verified.cs index e6b2d7c..ee781ad 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/NullableValueTests.UseAllowNullAttribute#JsonPolymorphicUnionAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/NullableValueTests.UseAllowNullAttribute#JsonPolymorphicUnionAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -12,6 +14,10 @@ namespace N.SourceGenerators.UnionTypes [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] internal sealed class JsonPolymorphicUnionAttribute : Attribute { +#if NETCOREAPP3_1_OR_GREATER public string? TypeDiscriminatorPropertyName { get; set; } +#else + public string TypeDiscriminatorPropertyName { get; set; } +#endif } } \ No newline at end of file diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/NullableValueTests.UseAllowNullAttribute#UnionConverterAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/NullableValueTests.UseAllowNullAttribute#UnionConverterAttribute.g.verified.cs index 3e6fd2b..973b6e2 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/NullableValueTests.UseAllowNullAttribute#UnionConverterAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/NullableValueTests.UseAllowNullAttribute#UnionConverterAttribute.g.verified.cs @@ -1,5 +1,7 @@ //HintName: UnionConverterAttribute.g.cs +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -10,9 +12,17 @@ sealed class UnionConverterAttribute : Attribute { public Type FromType { get; } public Type ToType { get; } +#if NETCOREAPP3_1_OR_GREATER public string? MethodName { get; } +#else + public string MethodName { get; } +#endif +#if NETCOREAPP3_1_OR_GREATER public UnionConverterAttribute(Type fromType, Type toType, string? methodName = null) +#else + public UnionConverterAttribute(Type fromType, Type toType, string methodName = null) +#endif { FromType = fromType; ToType = toType; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/NullableValueTests.UseAllowNullAttribute#UnionConverterFromAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/NullableValueTests.UseAllowNullAttribute#UnionConverterFromAttribute.g.verified.cs index d740ef3..222e936 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/NullableValueTests.UseAllowNullAttribute#UnionConverterFromAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/NullableValueTests.UseAllowNullAttribute#UnionConverterFromAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/NullableValueTests.UseAllowNullAttribute#UnionConverterToAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/NullableValueTests.UseAllowNullAttribute#UnionConverterToAttribute.g.verified.cs index fae1e4d..28901ff 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/NullableValueTests.UseAllowNullAttribute#UnionConverterToAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/NullableValueTests.UseAllowNullAttribute#UnionConverterToAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/NullableValueTests.UseAllowNullAttribute#UnionTypeAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/NullableValueTests.UseAllowNullAttribute#UnionTypeAttribute.g.verified.cs index 335ae09..927bc14 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/NullableValueTests.UseAllowNullAttribute#UnionTypeAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/NullableValueTests.UseAllowNullAttribute#UnionTypeAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -13,12 +15,24 @@ namespace N.SourceGenerators.UnionTypes internal sealed class UnionTypeAttribute : Attribute { public Type Type { get; } +#if NETCOREAPP3_1_OR_GREATER public string? Alias { get; } +#else + public string Alias { get; } +#endif public int Order { get; } public bool AllowNull { get; set; } +#if NETCOREAPP3_1_OR_GREATER public object? TypeDiscriminator { get; set; } +#else + public object TypeDiscriminator { get; set; } +#endif +#if NETCOREAPP3_1_OR_GREATER public UnionTypeAttribute(Type type, string? alias = null, [CallerLineNumber] int order = 0) +#else + public UnionTypeAttribute(Type type, string alias = null, [CallerLineNumber] int order = 0) +#endif { Type = type; Alias = alias; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/TwoAssemblyTests.UnionConverterFromInOtherAssembly_0#GenericUnionTypeAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/TwoAssemblyTests.UnionConverterFromInOtherAssembly_0#GenericUnionTypeAttribute.g.verified.cs index 9930562..17a28f9 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/TwoAssemblyTests.UnionConverterFromInOtherAssembly_0#GenericUnionTypeAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/TwoAssemblyTests.UnionConverterFromInOtherAssembly_0#GenericUnionTypeAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -12,8 +14,14 @@ namespace N.SourceGenerators.UnionTypes [AttributeUsage(AttributeTargets.GenericParameter, Inherited = false, AllowMultiple = false)] internal sealed class GenericUnionTypeAttribute : Attribute { +#if NETCOREAPP3_1_OR_GREATER public string? Alias { get; set; } public bool AllowNull { get; set; } public object? TypeDiscriminator { get; set; } +#else + public string Alias { get; set; } + public bool AllowNull { get; set; } + public object TypeDiscriminator { get; set; } +#endif } } \ No newline at end of file diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/TwoAssemblyTests.UnionConverterFromInOtherAssembly_0#JsonPolymorphicUnionAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/TwoAssemblyTests.UnionConverterFromInOtherAssembly_0#JsonPolymorphicUnionAttribute.g.verified.cs index e6b2d7c..ee781ad 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/TwoAssemblyTests.UnionConverterFromInOtherAssembly_0#JsonPolymorphicUnionAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/TwoAssemblyTests.UnionConverterFromInOtherAssembly_0#JsonPolymorphicUnionAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -12,6 +14,10 @@ namespace N.SourceGenerators.UnionTypes [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] internal sealed class JsonPolymorphicUnionAttribute : Attribute { +#if NETCOREAPP3_1_OR_GREATER public string? TypeDiscriminatorPropertyName { get; set; } +#else + public string TypeDiscriminatorPropertyName { get; set; } +#endif } } \ No newline at end of file diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/TwoAssemblyTests.UnionConverterFromInOtherAssembly_0#UnionConverterAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/TwoAssemblyTests.UnionConverterFromInOtherAssembly_0#UnionConverterAttribute.g.verified.cs index 3e6fd2b..973b6e2 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/TwoAssemblyTests.UnionConverterFromInOtherAssembly_0#UnionConverterAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/TwoAssemblyTests.UnionConverterFromInOtherAssembly_0#UnionConverterAttribute.g.verified.cs @@ -1,5 +1,7 @@ //HintName: UnionConverterAttribute.g.cs +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -10,9 +12,17 @@ sealed class UnionConverterAttribute : Attribute { public Type FromType { get; } public Type ToType { get; } +#if NETCOREAPP3_1_OR_GREATER public string? MethodName { get; } +#else + public string MethodName { get; } +#endif +#if NETCOREAPP3_1_OR_GREATER public UnionConverterAttribute(Type fromType, Type toType, string? methodName = null) +#else + public UnionConverterAttribute(Type fromType, Type toType, string methodName = null) +#endif { FromType = fromType; ToType = toType; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/TwoAssemblyTests.UnionConverterFromInOtherAssembly_0#UnionConverterFromAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/TwoAssemblyTests.UnionConverterFromInOtherAssembly_0#UnionConverterFromAttribute.g.verified.cs index d740ef3..222e936 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/TwoAssemblyTests.UnionConverterFromInOtherAssembly_0#UnionConverterFromAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/TwoAssemblyTests.UnionConverterFromInOtherAssembly_0#UnionConverterFromAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/TwoAssemblyTests.UnionConverterFromInOtherAssembly_0#UnionConverterToAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/TwoAssemblyTests.UnionConverterFromInOtherAssembly_0#UnionConverterToAttribute.g.verified.cs index fae1e4d..28901ff 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/TwoAssemblyTests.UnionConverterFromInOtherAssembly_0#UnionConverterToAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/TwoAssemblyTests.UnionConverterFromInOtherAssembly_0#UnionConverterToAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/TwoAssemblyTests.UnionConverterFromInOtherAssembly_0#UnionTypeAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/TwoAssemblyTests.UnionConverterFromInOtherAssembly_0#UnionTypeAttribute.g.verified.cs index 335ae09..927bc14 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/TwoAssemblyTests.UnionConverterFromInOtherAssembly_0#UnionTypeAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/TwoAssemblyTests.UnionConverterFromInOtherAssembly_0#UnionTypeAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -13,12 +15,24 @@ namespace N.SourceGenerators.UnionTypes internal sealed class UnionTypeAttribute : Attribute { public Type Type { get; } +#if NETCOREAPP3_1_OR_GREATER public string? Alias { get; } +#else + public string Alias { get; } +#endif public int Order { get; } public bool AllowNull { get; set; } +#if NETCOREAPP3_1_OR_GREATER public object? TypeDiscriminator { get; set; } +#else + public object TypeDiscriminator { get; set; } +#endif +#if NETCOREAPP3_1_OR_GREATER public UnionTypeAttribute(Type type, string? alias = null, [CallerLineNumber] int order = 0) +#else + public UnionTypeAttribute(Type type, string alias = null, [CallerLineNumber] int order = 0) +#endif { Type = type; Alias = alias; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/TwoAssemblyTests.UnionConverterFromInOtherAssembly_1#GenericUnionTypeAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/TwoAssemblyTests.UnionConverterFromInOtherAssembly_1#GenericUnionTypeAttribute.g.verified.cs index 9930562..17a28f9 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/TwoAssemblyTests.UnionConverterFromInOtherAssembly_1#GenericUnionTypeAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/TwoAssemblyTests.UnionConverterFromInOtherAssembly_1#GenericUnionTypeAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -12,8 +14,14 @@ namespace N.SourceGenerators.UnionTypes [AttributeUsage(AttributeTargets.GenericParameter, Inherited = false, AllowMultiple = false)] internal sealed class GenericUnionTypeAttribute : Attribute { +#if NETCOREAPP3_1_OR_GREATER public string? Alias { get; set; } public bool AllowNull { get; set; } public object? TypeDiscriminator { get; set; } +#else + public string Alias { get; set; } + public bool AllowNull { get; set; } + public object TypeDiscriminator { get; set; } +#endif } } \ No newline at end of file diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/TwoAssemblyTests.UnionConverterFromInOtherAssembly_1#JsonPolymorphicUnionAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/TwoAssemblyTests.UnionConverterFromInOtherAssembly_1#JsonPolymorphicUnionAttribute.g.verified.cs index e6b2d7c..ee781ad 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/TwoAssemblyTests.UnionConverterFromInOtherAssembly_1#JsonPolymorphicUnionAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/TwoAssemblyTests.UnionConverterFromInOtherAssembly_1#JsonPolymorphicUnionAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -12,6 +14,10 @@ namespace N.SourceGenerators.UnionTypes [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] internal sealed class JsonPolymorphicUnionAttribute : Attribute { +#if NETCOREAPP3_1_OR_GREATER public string? TypeDiscriminatorPropertyName { get; set; } +#else + public string TypeDiscriminatorPropertyName { get; set; } +#endif } } \ No newline at end of file diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/TwoAssemblyTests.UnionConverterFromInOtherAssembly_1#UnionConverterAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/TwoAssemblyTests.UnionConverterFromInOtherAssembly_1#UnionConverterAttribute.g.verified.cs index 3e6fd2b..973b6e2 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/TwoAssemblyTests.UnionConverterFromInOtherAssembly_1#UnionConverterAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/TwoAssemblyTests.UnionConverterFromInOtherAssembly_1#UnionConverterAttribute.g.verified.cs @@ -1,5 +1,7 @@ //HintName: UnionConverterAttribute.g.cs +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -10,9 +12,17 @@ sealed class UnionConverterAttribute : Attribute { public Type FromType { get; } public Type ToType { get; } +#if NETCOREAPP3_1_OR_GREATER public string? MethodName { get; } +#else + public string MethodName { get; } +#endif +#if NETCOREAPP3_1_OR_GREATER public UnionConverterAttribute(Type fromType, Type toType, string? methodName = null) +#else + public UnionConverterAttribute(Type fromType, Type toType, string methodName = null) +#endif { FromType = fromType; ToType = toType; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/TwoAssemblyTests.UnionConverterFromInOtherAssembly_1#UnionConverterFromAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/TwoAssemblyTests.UnionConverterFromInOtherAssembly_1#UnionConverterFromAttribute.g.verified.cs index d740ef3..222e936 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/TwoAssemblyTests.UnionConverterFromInOtherAssembly_1#UnionConverterFromAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/TwoAssemblyTests.UnionConverterFromInOtherAssembly_1#UnionConverterFromAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/TwoAssemblyTests.UnionConverterFromInOtherAssembly_1#UnionConverterToAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/TwoAssemblyTests.UnionConverterFromInOtherAssembly_1#UnionConverterToAttribute.g.verified.cs index fae1e4d..28901ff 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/TwoAssemblyTests.UnionConverterFromInOtherAssembly_1#UnionConverterToAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/TwoAssemblyTests.UnionConverterFromInOtherAssembly_1#UnionConverterToAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/TwoAssemblyTests.UnionConverterFromInOtherAssembly_1#UnionTypeAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/TwoAssemblyTests.UnionConverterFromInOtherAssembly_1#UnionTypeAttribute.g.verified.cs index 335ae09..927bc14 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/TwoAssemblyTests.UnionConverterFromInOtherAssembly_1#UnionTypeAttribute.g.verified.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/TwoAssemblyTests.UnionConverterFromInOtherAssembly_1#UnionTypeAttribute.g.verified.cs @@ -3,7 +3,9 @@ // This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes // Feel free to open an issue // +#if NETCOREAPP3_1_OR_GREATER #nullable enable +#endif using System; using System.Runtime.CompilerServices; @@ -13,12 +15,24 @@ namespace N.SourceGenerators.UnionTypes internal sealed class UnionTypeAttribute : Attribute { public Type Type { get; } +#if NETCOREAPP3_1_OR_GREATER public string? Alias { get; } +#else + public string Alias { get; } +#endif public int Order { get; } public bool AllowNull { get; set; } +#if NETCOREAPP3_1_OR_GREATER public object? TypeDiscriminator { get; set; } +#else + public object TypeDiscriminator { get; set; } +#endif +#if NETCOREAPP3_1_OR_GREATER public UnionTypeAttribute(Type type, string? alias = null, [CallerLineNumber] int order = 0) +#else + public UnionTypeAttribute(Type type, string alias = null, [CallerLineNumber] int order = 0) +#endif { Type = type; Alias = alias; diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/TestHelper.cs b/tests/N.SourceGenerators.UnionTypes.Tests/TestHelper.cs index 29a6c90..6126649 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/TestHelper.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/TestHelper.cs @@ -48,7 +48,7 @@ public static async Task Verify( syntaxTrees: new[] { syntaxTree }, references, new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary)); - + if (previousCompilation != null) { compilation = compilation.AddReferences(previousCompilation.ToMetadataReference()); From b9b53047041056aac4be4460903035499ba3297b Mon Sep 17 00:00:00 2001 From: Alexey Sosnin Date: Tue, 19 Mar 2024 20:43:11 +0300 Subject: [PATCH 2/2] fix: struct union types for netstandard2.0 --- examples/LegacyFramework/Result.cs | 6 + .../Models/CompilationContext.cs | 7 + .../Models/UnionType.cs | 4 +- .../UnionTypesGenerator.EqualityMembers.cs | 4 +- .../UnionTypesGenerator.cs | 14 +- .../GeneratorTests.cs | 37 +- .../JsonTests.cs | 4 +- ...ss#GenericUnionTypeAttribute.g.verified.cs | 27 ++ ...sonPolymorphicUnionAttribute.g.verified.cs | 23 + ...Sharp73_partial-class#Result.g.verified.cs | 440 ++++++++++++++++++ ...lass#UnionConverterAttribute.g.verified.cs | 32 ++ ...#UnionConverterFromAttribute.g.verified.cs | 24 + ...ss#UnionConverterToAttribute.g.verified.cs | 24 + ...ial-class#UnionTypeAttribute.g.verified.cs | 42 ++ ...ct#GenericUnionTypeAttribute.g.verified.cs | 27 ++ ...sonPolymorphicUnionAttribute.g.verified.cs | 23 + ...harp73_partial-struct#Result.g.verified.cs | 435 +++++++++++++++++ ...ruct#UnionConverterAttribute.g.verified.cs | 32 ++ ...#UnionConverterFromAttribute.g.verified.cs | 24 + ...ct#UnionConverterToAttribute.g.verified.cs | 24 + ...al-struct#UnionTypeAttribute.g.verified.cs | 42 ++ .../TestHelper.cs | 18 +- 22 files changed, 1294 insertions(+), 19 deletions(-) create mode 100644 src/N.SourceGenerators.UnionTypes/Models/CompilationContext.cs create mode 100644 tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.CSharp73_partial-class#GenericUnionTypeAttribute.g.verified.cs create mode 100644 tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.CSharp73_partial-class#JsonPolymorphicUnionAttribute.g.verified.cs create mode 100644 tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.CSharp73_partial-class#Result.g.verified.cs create mode 100644 tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.CSharp73_partial-class#UnionConverterAttribute.g.verified.cs create mode 100644 tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.CSharp73_partial-class#UnionConverterFromAttribute.g.verified.cs create mode 100644 tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.CSharp73_partial-class#UnionConverterToAttribute.g.verified.cs create mode 100644 tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.CSharp73_partial-class#UnionTypeAttribute.g.verified.cs create mode 100644 tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.CSharp73_partial-struct#GenericUnionTypeAttribute.g.verified.cs create mode 100644 tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.CSharp73_partial-struct#JsonPolymorphicUnionAttribute.g.verified.cs create mode 100644 tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.CSharp73_partial-struct#Result.g.verified.cs create mode 100644 tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.CSharp73_partial-struct#UnionConverterAttribute.g.verified.cs create mode 100644 tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.CSharp73_partial-struct#UnionConverterFromAttribute.g.verified.cs create mode 100644 tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.CSharp73_partial-struct#UnionConverterToAttribute.g.verified.cs create mode 100644 tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.CSharp73_partial-struct#UnionTypeAttribute.g.verified.cs diff --git a/examples/LegacyFramework/Result.cs b/examples/LegacyFramework/Result.cs index ff88056..cf875de 100644 --- a/examples/LegacyFramework/Result.cs +++ b/examples/LegacyFramework/Result.cs @@ -16,4 +16,10 @@ public class Bar public partial class Result { } + + [UnionType(typeof(Foo))] + [UnionType(typeof(Bar))] + public partial struct StructResult + { + } } \ No newline at end of file diff --git a/src/N.SourceGenerators.UnionTypes/Models/CompilationContext.cs b/src/N.SourceGenerators.UnionTypes/Models/CompilationContext.cs new file mode 100644 index 0000000..edb63f5 --- /dev/null +++ b/src/N.SourceGenerators.UnionTypes/Models/CompilationContext.cs @@ -0,0 +1,7 @@ +namespace N.SourceGenerators.UnionTypes.Models; + +internal record CompilationContext( + bool SupportsNotNullWhenAttribute, + bool SupportsThrowIfNull, + bool NullableContextEnabled, + bool SupportsAutoDefaultField); \ No newline at end of file diff --git a/src/N.SourceGenerators.UnionTypes/Models/UnionType.cs b/src/N.SourceGenerators.UnionTypes/Models/UnionType.cs index 150e0f9..f4cd1a8 100644 --- a/src/N.SourceGenerators.UnionTypes/Models/UnionType.cs +++ b/src/N.SourceGenerators.UnionTypes/Models/UnionType.cs @@ -150,6 +150,4 @@ public int GetHashCode(UnionType obj) { return obj.TypeFullName.GetHashCode(); } -} - -internal record CompilationContext(bool SupportsNotNullWhenAttribute, bool SupportsThrowIfNull, bool NullableContextEnabled); \ No newline at end of file +} \ No newline at end of file diff --git a/src/N.SourceGenerators.UnionTypes/UnionTypesGenerator.EqualityMembers.cs b/src/N.SourceGenerators.UnionTypes/UnionTypesGenerator.EqualityMembers.cs index 7d84329..84c9f4a 100644 --- a/src/N.SourceGenerators.UnionTypes/UnionTypesGenerator.EqualityMembers.cs +++ b/src/N.SourceGenerators.UnionTypes/UnionTypesGenerator.EqualityMembers.cs @@ -174,7 +174,7 @@ IEnumerable BodyStatements() } } - private static MemberDeclarationSyntax StructEqualsMethod(UnionType unionType) + private static MemberDeclarationSyntax StructEqualsMethod(UnionType unionType, CompilationContext compilationContext) { return MethodDeclaration( IdentifierName("bool"), @@ -183,7 +183,7 @@ private static MemberDeclarationSyntax StructEqualsMethod(UnionType unionType) Token(SyntaxKind.PublicKeyword), Token(SyntaxKind.OverrideKeyword) ).AddParameterListParameters( - Parameter(NullableType(ObjectType()), "obj") + Parameter(ObjectType().NullableTypeWhen(compilationContext.NullableContextEnabled), "obj") ).AddBodyStatements( ReturnStatement( BinaryExpression( diff --git a/src/N.SourceGenerators.UnionTypes/UnionTypesGenerator.cs b/src/N.SourceGenerators.UnionTypes/UnionTypesGenerator.cs index 310f9cb..8f4bba0 100644 --- a/src/N.SourceGenerators.UnionTypes/UnionTypesGenerator.cs +++ b/src/N.SourceGenerators.UnionTypes/UnionTypesGenerator.cs @@ -31,7 +31,8 @@ public void Initialize(IncrementalGeneratorInitializationContext context) var supportsNotNullWhenAttribute = compilation.GetTypeByMetadataName("System.Diagnostics.CodeAnalysis.NotNullWhenAttribute") != null; var supportsThrowIfNull = compilation.GetTypeByMetadataName("System.ArgumentNullException")?.GetMembers("ThrowIfNull").Any() ?? false; var nullableContextEnabled = compilation.HasLanguageVersionAtLeastEqualTo(LanguageVersion.CSharp8); - CompilationContext compilationContext = new(supportsNotNullWhenAttribute, supportsThrowIfNull, nullableContextEnabled); + var supportsAutoDefaultField = compilation.HasLanguageVersionAtLeastEqualTo(LanguageVersion.CSharp11); + CompilationContext compilationContext = new(supportsNotNullWhenAttribute, supportsThrowIfNull, nullableContextEnabled, supportsAutoDefaultField); return compilationContext; }); @@ -262,7 +263,7 @@ static void GenerateUnionType(UnionType unionType, ) .AddMembersWhen(!unionType.HasToStringMethod, ToStringMethod(unionType)) .AddMembersWhen(unionType.IsReferenceType, ClassEqualsMethod(unionType, compilationContext)) - .AddMembersWhen(!unionType.IsReferenceType, StructEqualsMethod(unionType)) + .AddMembersWhen(!unionType.IsReferenceType, StructEqualsMethod(unionType, compilationContext)) .WithBaseList( BaseList( SeparatedList( @@ -545,6 +546,10 @@ private static MemberDeclarationSyntax Ctor(UnionType unionType, UnionTypeVarian variant.FieldName, variant.ParameterName); + var initOtherVariants = unionType.Variants.Except([variant]) + .Select(otherVariant => SimpleAssignmentExpression(otherVariant.FieldName, DefaultExpression(IdentifierName(otherVariant.TypeFullName)))) + .Select(ExpressionStatement); + return ConstructorDeclaration(Identifier(unionType.NameNoGenerics)) .AddModifiers(Token(SyntaxKind.PublicKeyword)) .AddParameterListParameters( @@ -560,7 +565,10 @@ private static MemberDeclarationSyntax Ctor(UnionType unionType, UnionTypeVarian variant.IdConstName))) .AddBodyStatements( ExpressionStatement(assignmentExpression) - ); + ) + .AddBodyStatementsWhen( + !compilationContext.SupportsAutoDefaultField && unionType.IsValueType, + initOtherVariants.Cast().ToArray()); } private static ConversionOperatorDeclarationSyntax ImplicitOperatorToUnion(UnionType unionType, diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/GeneratorTests.cs b/tests/N.SourceGenerators.UnionTypes.Tests/GeneratorTests.cs index bf45b53..63be26c 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/GeneratorTests.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/GeneratorTests.cs @@ -1,3 +1,5 @@ +using Microsoft.CodeAnalysis.CSharp; + namespace N.SourceGenerators.UnionTypes.Tests; [UsesVerify] @@ -26,7 +28,7 @@ public record Wrapped(TItem Item); } """; - return TestHelper.Verify(source, typeModifiers.Replace(' ', '-')); + return TestHelper.Verify(source, LanguageVersion.Latest, typeModifiers.Replace(' ', '-')); } [Theory] @@ -56,7 +58,7 @@ public record Error; } """; - return TestHelper.Verify(source, typeModifiers.Replace(' ', '-')); + return TestHelper.Verify(source, LanguageVersion.Latest, typeModifiers.Replace(' ', '-')); } [Fact] @@ -146,11 +148,36 @@ public override string ToString() } """; - return TestHelper.Verify(source, typeModifiers.Replace(' ', '-')); + return TestHelper.Verify(source, LanguageVersion.Latest, typeModifiers.Replace(' ', '-')); } - public int ToString(int a) + + [Theory] + [InlineData("partial class")] + [InlineData("partial struct")] + public Task CSharp73(string typeModifiers) { - return 0; + string source = $$""" +using System; +using System.Collections.Generic; +using N.SourceGenerators.UnionTypes; + +namespace MyApp +{ + public class Success{}; + public class Error{}; + + [UnionType(typeof(Success))] + [UnionType(typeof(Error))] + [UnionType(typeof(IReadOnlyList))] + [UnionType(typeof(string[]))] + [UnionType(typeof(Tuple))] + public {{typeModifiers}} Result + { + } +} +"""; + + return TestHelper.Verify(source, LanguageVersion.CSharp7_3, typeModifiers.Replace(' ', '-')); } } \ No newline at end of file diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/JsonTests.cs b/tests/N.SourceGenerators.UnionTypes.Tests/JsonTests.cs index 663b91c..417d3fe 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/JsonTests.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/JsonTests.cs @@ -1,6 +1,7 @@ using System.Reflection; using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp; namespace N.SourceGenerators.UnionTypes.Tests; @@ -34,7 +35,8 @@ public partial class JsonTestsUnion """; return TestHelper.Verify( - source, + source, + LanguageVersion.Latest, null, MetadataReference.CreateFromFile(Assembly.Load(new AssemblyName("System.Runtime")).Location), MetadataReference.CreateFromFile(Assembly.Load(new AssemblyName("System.Text.Json")).Location), diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.CSharp73_partial-class#GenericUnionTypeAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.CSharp73_partial-class#GenericUnionTypeAttribute.g.verified.cs new file mode 100644 index 0000000..17a28f9 --- /dev/null +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.CSharp73_partial-class#GenericUnionTypeAttribute.g.verified.cs @@ -0,0 +1,27 @@ +//HintName: GenericUnionTypeAttribute.g.cs +// +// This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes +// Feel free to open an issue +// +#if NETCOREAPP3_1_OR_GREATER +#nullable enable +#endif +using System; +using System.Runtime.CompilerServices; + +namespace N.SourceGenerators.UnionTypes +{ + [AttributeUsage(AttributeTargets.GenericParameter, Inherited = false, AllowMultiple = false)] + internal sealed class GenericUnionTypeAttribute : Attribute + { +#if NETCOREAPP3_1_OR_GREATER + public string? Alias { get; set; } + public bool AllowNull { get; set; } + public object? TypeDiscriminator { get; set; } +#else + public string Alias { get; set; } + public bool AllowNull { get; set; } + public object TypeDiscriminator { get; set; } +#endif + } +} \ No newline at end of file diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.CSharp73_partial-class#JsonPolymorphicUnionAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.CSharp73_partial-class#JsonPolymorphicUnionAttribute.g.verified.cs new file mode 100644 index 0000000..ee781ad --- /dev/null +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.CSharp73_partial-class#JsonPolymorphicUnionAttribute.g.verified.cs @@ -0,0 +1,23 @@ +//HintName: JsonPolymorphicUnionAttribute.g.cs +// +// This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes +// Feel free to open an issue +// +#if NETCOREAPP3_1_OR_GREATER +#nullable enable +#endif +using System; +using System.Runtime.CompilerServices; + +namespace N.SourceGenerators.UnionTypes +{ + [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + internal sealed class JsonPolymorphicUnionAttribute : Attribute + { +#if NETCOREAPP3_1_OR_GREATER + public string? TypeDiscriminatorPropertyName { get; set; } +#else + public string TypeDiscriminatorPropertyName { get; set; } +#endif + } +} \ No newline at end of file diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.CSharp73_partial-class#Result.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.CSharp73_partial-class#Result.g.verified.cs new file mode 100644 index 0000000..0ce6bf1 --- /dev/null +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.CSharp73_partial-class#Result.g.verified.cs @@ -0,0 +1,440 @@ +//HintName: Result.g.cs +// +// This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes +// Feel free to open an issue +// +#pragma warning disable +namespace MyApp +{ + partial class Result : System.IEquatable + { + private readonly int _variantId; + private const int SuccessId = 1; + private readonly global::MyApp.Success _success; + public bool IsSuccess => _variantId == SuccessId; + public global::MyApp.Success AsSuccess + { + get + { + if (_variantId == SuccessId) + return _success; + throw new System.InvalidOperationException($"Unable convert to Success. Inner value is {ValueAlias} not Success."); + } + } + + public Result(global::MyApp.Success success) + { + System.ArgumentNullException.ThrowIfNull(success); + _variantId = SuccessId; + _success = success; + } + + public static implicit operator Result(global::MyApp.Success success) => new Result(success); + public static explicit operator global::MyApp.Success(Result value) + { + if (value._variantId == SuccessId) + return value._success; + throw new System.InvalidOperationException($"Unable convert to Success. Inner value is {value.ValueAlias} not Success."); + } + + public bool TryGetSuccess([System.Diagnostics.CodeAnalysis.NotNullWhen(true)] out global::MyApp.Success value) + { + if (_variantId == SuccessId) + { + value = _success; + return true; + } + else + { + value = default; + return false; + } + } + + private const int ErrorId = 2; + private readonly global::MyApp.Error _error; + public bool IsError => _variantId == ErrorId; + public global::MyApp.Error AsError + { + get + { + if (_variantId == ErrorId) + return _error; + throw new System.InvalidOperationException($"Unable convert to Error. Inner value is {ValueAlias} not Error."); + } + } + + public Result(global::MyApp.Error @error) + { + System.ArgumentNullException.ThrowIfNull(@error); + _variantId = ErrorId; + _error = @error; + } + + public static implicit operator Result(global::MyApp.Error @error) => new Result(@error); + public static explicit operator global::MyApp.Error(Result value) + { + if (value._variantId == ErrorId) + return value._error; + throw new System.InvalidOperationException($"Unable convert to Error. Inner value is {value.ValueAlias} not Error."); + } + + public bool TryGetError([System.Diagnostics.CodeAnalysis.NotNullWhen(true)] out global::MyApp.Error value) + { + if (_variantId == ErrorId) + { + value = _error; + return true; + } + else + { + value = default; + return false; + } + } + + private const int IReadOnlyListOfInt32Id = 3; + private readonly global::System.Collections.Generic.IReadOnlyList _iReadOnlyListOfInt32; + public bool IsIReadOnlyListOfInt32 => _variantId == IReadOnlyListOfInt32Id; + public global::System.Collections.Generic.IReadOnlyList AsIReadOnlyListOfInt32 + { + get + { + if (_variantId == IReadOnlyListOfInt32Id) + return _iReadOnlyListOfInt32; + throw new System.InvalidOperationException($"Unable convert to IReadOnlyListOfInt32. Inner value is {ValueAlias} not IReadOnlyListOfInt32."); + } + } + + public Result(global::System.Collections.Generic.IReadOnlyList iReadOnlyListOfInt32) + { + System.ArgumentNullException.ThrowIfNull(iReadOnlyListOfInt32); + _variantId = IReadOnlyListOfInt32Id; + _iReadOnlyListOfInt32 = iReadOnlyListOfInt32; + } + + public bool TryGetIReadOnlyListOfInt32([System.Diagnostics.CodeAnalysis.NotNullWhen(true)] out global::System.Collections.Generic.IReadOnlyList value) + { + if (_variantId == IReadOnlyListOfInt32Id) + { + value = _iReadOnlyListOfInt32; + return true; + } + else + { + value = default; + return false; + } + } + + private const int ArrayOfStringId = 4; + private readonly string[] _arrayOfString; + public bool IsArrayOfString => _variantId == ArrayOfStringId; + public string[] AsArrayOfString + { + get + { + if (_variantId == ArrayOfStringId) + return _arrayOfString; + throw new System.InvalidOperationException($"Unable convert to ArrayOfString. Inner value is {ValueAlias} not ArrayOfString."); + } + } + + public Result(string[] arrayOfString) + { + System.ArgumentNullException.ThrowIfNull(arrayOfString); + _variantId = ArrayOfStringId; + _arrayOfString = arrayOfString; + } + + public static implicit operator Result(string[] arrayOfString) => new Result(arrayOfString); + public static explicit operator string[](Result value) + { + if (value._variantId == ArrayOfStringId) + return value._arrayOfString; + throw new System.InvalidOperationException($"Unable convert to ArrayOfString. Inner value is {value.ValueAlias} not ArrayOfString."); + } + + public bool TryGetArrayOfString([System.Diagnostics.CodeAnalysis.NotNullWhen(true)] out string[] value) + { + if (_variantId == ArrayOfStringId) + { + value = _arrayOfString; + return true; + } + else + { + value = default; + return false; + } + } + + private const int TupleOfInt32AndStringId = 5; + private readonly global::System.Tuple _tupleOfInt32AndString; + public bool IsTupleOfInt32AndString => _variantId == TupleOfInt32AndStringId; + public global::System.Tuple AsTupleOfInt32AndString + { + get + { + if (_variantId == TupleOfInt32AndStringId) + return _tupleOfInt32AndString; + throw new System.InvalidOperationException($"Unable convert to TupleOfInt32AndString. Inner value is {ValueAlias} not TupleOfInt32AndString."); + } + } + + public Result(global::System.Tuple tupleOfInt32AndString) + { + System.ArgumentNullException.ThrowIfNull(tupleOfInt32AndString); + _variantId = TupleOfInt32AndStringId; + _tupleOfInt32AndString = tupleOfInt32AndString; + } + + public static implicit operator Result(global::System.Tuple tupleOfInt32AndString) => new Result(tupleOfInt32AndString); + public static explicit operator global::System.Tuple(Result value) + { + if (value._variantId == TupleOfInt32AndStringId) + return value._tupleOfInt32AndString; + throw new System.InvalidOperationException($"Unable convert to TupleOfInt32AndString. Inner value is {value.ValueAlias} not TupleOfInt32AndString."); + } + + public bool TryGetTupleOfInt32AndString([System.Diagnostics.CodeAnalysis.NotNullWhen(true)] out global::System.Tuple value) + { + if (_variantId == TupleOfInt32AndStringId) + { + value = _tupleOfInt32AndString; + return true; + } + else + { + value = default; + return false; + } + } + + public TOut Match(global::System.Func matchSuccess, global::System.Func matchError, global::System.Func, TOut> matchIReadOnlyListOfInt32, global::System.Func matchArrayOfString, global::System.Func, TOut> matchTupleOfInt32AndString) + { + if (_variantId == SuccessId) + return matchSuccess(_success); + if (_variantId == ErrorId) + return matchError(_error); + if (_variantId == IReadOnlyListOfInt32Id) + return matchIReadOnlyListOfInt32(_iReadOnlyListOfInt32); + if (_variantId == ArrayOfStringId) + return matchArrayOfString(_arrayOfString); + if (_variantId == TupleOfInt32AndStringId) + return matchTupleOfInt32AndString(_tupleOfInt32AndString); + throw new System.InvalidOperationException("Inner type is unknown"); + } + + public async global::System.Threading.Tasks.Task MatchAsync(global::System.Func> matchSuccess, global::System.Func> matchError, global::System.Func, global::System.Threading.CancellationToken, global::System.Threading.Tasks.Task> matchIReadOnlyListOfInt32, global::System.Func> matchArrayOfString, global::System.Func, global::System.Threading.CancellationToken, global::System.Threading.Tasks.Task> matchTupleOfInt32AndString, global::System.Threading.CancellationToken ct) + { + if (_variantId == SuccessId) + return await matchSuccess(_success, ct).ConfigureAwait(false); + if (_variantId == ErrorId) + return await matchError(_error, ct).ConfigureAwait(false); + if (_variantId == IReadOnlyListOfInt32Id) + return await matchIReadOnlyListOfInt32(_iReadOnlyListOfInt32, ct).ConfigureAwait(false); + if (_variantId == ArrayOfStringId) + return await matchArrayOfString(_arrayOfString, ct).ConfigureAwait(false); + if (_variantId == TupleOfInt32AndStringId) + return await matchTupleOfInt32AndString(_tupleOfInt32AndString, ct).ConfigureAwait(false); + throw new System.InvalidOperationException("Inner type is unknown"); + } + + public void Switch(global::System.Action switchSuccess, global::System.Action switchError, global::System.Action> switchIReadOnlyListOfInt32, global::System.Action switchArrayOfString, global::System.Action> switchTupleOfInt32AndString) + { + if (_variantId == SuccessId) + { + switchSuccess(_success); + return; + } + + if (_variantId == ErrorId) + { + switchError(_error); + return; + } + + if (_variantId == IReadOnlyListOfInt32Id) + { + switchIReadOnlyListOfInt32(_iReadOnlyListOfInt32); + return; + } + + if (_variantId == ArrayOfStringId) + { + switchArrayOfString(_arrayOfString); + return; + } + + if (_variantId == TupleOfInt32AndStringId) + { + switchTupleOfInt32AndString(_tupleOfInt32AndString); + return; + } + + throw new System.InvalidOperationException("Inner type is unknown"); + } + + public async global::System.Threading.Tasks.Task SwitchAsync(global::System.Func switchSuccess, global::System.Func switchError, global::System.Func, global::System.Threading.CancellationToken, global::System.Threading.Tasks.Task> switchIReadOnlyListOfInt32, global::System.Func switchArrayOfString, global::System.Func, global::System.Threading.CancellationToken, global::System.Threading.Tasks.Task> switchTupleOfInt32AndString, global::System.Threading.CancellationToken ct) + { + if (_variantId == SuccessId) + { + await switchSuccess(_success, ct).ConfigureAwait(false); + return; + } + + if (_variantId == ErrorId) + { + await switchError(_error, ct).ConfigureAwait(false); + return; + } + + if (_variantId == IReadOnlyListOfInt32Id) + { + await switchIReadOnlyListOfInt32(_iReadOnlyListOfInt32, ct).ConfigureAwait(false); + return; + } + + if (_variantId == ArrayOfStringId) + { + await switchArrayOfString(_arrayOfString, ct).ConfigureAwait(false); + return; + } + + if (_variantId == TupleOfInt32AndStringId) + { + await switchTupleOfInt32AndString(_tupleOfInt32AndString, ct).ConfigureAwait(false); + return; + } + + throw new System.InvalidOperationException("Inner type is unknown"); + } + + public global::System.Type ValueType + { + get + { + if (_variantId == SuccessId) + return typeof(global::MyApp.Success); + if (_variantId == ErrorId) + return typeof(global::MyApp.Error); + if (_variantId == IReadOnlyListOfInt32Id) + return typeof(global::System.Collections.Generic.IReadOnlyList); + if (_variantId == ArrayOfStringId) + return typeof(string[]); + if (_variantId == TupleOfInt32AndStringId) + return typeof(global::System.Tuple); + throw new System.InvalidOperationException("Inner type is unknown"); + } + } + + private string ValueAlias + { + get + { + if (_variantId == SuccessId) + return "Success"; + if (_variantId == ErrorId) + return "Error"; + if (_variantId == IReadOnlyListOfInt32Id) + return "IReadOnlyListOfInt32"; + if (_variantId == ArrayOfStringId) + return "ArrayOfString"; + if (_variantId == TupleOfInt32AndStringId) + return "TupleOfInt32AndString"; + throw new System.InvalidOperationException("Inner type is unknown"); + } + } + + public override int GetHashCode() + { + if (_variantId == SuccessId) + return _success.GetHashCode(); + if (_variantId == ErrorId) + return _error.GetHashCode(); + if (_variantId == IReadOnlyListOfInt32Id) + return _iReadOnlyListOfInt32.GetHashCode(); + if (_variantId == ArrayOfStringId) + return _arrayOfString.GetHashCode(); + if (_variantId == TupleOfInt32AndStringId) + return _tupleOfInt32AndString.GetHashCode(); + throw new System.InvalidOperationException("Inner type is unknown"); + } + + public static bool operator ==(Result left, Result right) + { + return Equals(left, right); + } + + public static bool operator !=(Result left, Result right) + { + return !Equals(left, right); + } + + public bool Equals(Result other) + { + if (ReferenceEquals(null, other)) + { + return false; + } + + if (ReferenceEquals(this, other)) + { + return true; + } + + if (ValueType != other.ValueType) + { + return false; + } + + if (_variantId == SuccessId) + return System.Collections.Generic.EqualityComparer.Default.Equals(_success, other._success); + if (_variantId == ErrorId) + return System.Collections.Generic.EqualityComparer.Default.Equals(_error, other._error); + if (_variantId == IReadOnlyListOfInt32Id) + return System.Collections.Generic.EqualityComparer>.Default.Equals(_iReadOnlyListOfInt32, other._iReadOnlyListOfInt32); + if (_variantId == ArrayOfStringId) + return System.Collections.Generic.EqualityComparer.Default.Equals(_arrayOfString, other._arrayOfString); + if (_variantId == TupleOfInt32AndStringId) + return System.Collections.Generic.EqualityComparer>.Default.Equals(_tupleOfInt32AndString, other._tupleOfInt32AndString); + throw new System.InvalidOperationException("Inner type is unknown"); + } + + public override string ToString() + { + if (_variantId == SuccessId) + return _success.ToString(); + if (_variantId == ErrorId) + return _error.ToString(); + if (_variantId == IReadOnlyListOfInt32Id) + return _iReadOnlyListOfInt32.ToString(); + if (_variantId == ArrayOfStringId) + return _arrayOfString.ToString(); + if (_variantId == TupleOfInt32AndStringId) + return _tupleOfInt32AndString.ToString(); + throw new System.InvalidOperationException("Inner type is unknown"); + } + + public override bool Equals(object other) + { + if (ReferenceEquals(null, other)) + { + return false; + } + + if (ReferenceEquals(this, other)) + { + return true; + } + + if (other.GetType() != typeof(Result)) + { + return false; + } + + return Equals((Result)other); + } + } +} \ No newline at end of file diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.CSharp73_partial-class#UnionConverterAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.CSharp73_partial-class#UnionConverterAttribute.g.verified.cs new file mode 100644 index 0000000..973b6e2 --- /dev/null +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.CSharp73_partial-class#UnionConverterAttribute.g.verified.cs @@ -0,0 +1,32 @@ +//HintName: UnionConverterAttribute.g.cs +#if NETCOREAPP3_1_OR_GREATER +#nullable enable +#endif +using System; +using System.Runtime.CompilerServices; + +namespace N.SourceGenerators.UnionTypes +{ + [AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = true)] + sealed class UnionConverterAttribute : Attribute + { + public Type FromType { get; } + public Type ToType { get; } +#if NETCOREAPP3_1_OR_GREATER + public string? MethodName { get; } +#else + public string MethodName { get; } +#endif + +#if NETCOREAPP3_1_OR_GREATER + public UnionConverterAttribute(Type fromType, Type toType, string? methodName = null) +#else + public UnionConverterAttribute(Type fromType, Type toType, string methodName = null) +#endif + { + FromType = fromType; + ToType = toType; + MethodName = methodName; + } + } +} \ No newline at end of file diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.CSharp73_partial-class#UnionConverterFromAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.CSharp73_partial-class#UnionConverterFromAttribute.g.verified.cs new file mode 100644 index 0000000..222e936 --- /dev/null +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.CSharp73_partial-class#UnionConverterFromAttribute.g.verified.cs @@ -0,0 +1,24 @@ +//HintName: UnionConverterFromAttribute.g.cs +// +// This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes +// Feel free to open an issue +// +#if NETCOREAPP3_1_OR_GREATER +#nullable enable +#endif +using System; +using System.Runtime.CompilerServices; + +namespace N.SourceGenerators.UnionTypes +{ + [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, Inherited = false, AllowMultiple = true)] + sealed class UnionConverterFromAttribute : Attribute + { + public Type FromType { get; } + + public UnionConverterFromAttribute(Type fromType) + { + FromType = fromType; + } + } +} \ No newline at end of file diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.CSharp73_partial-class#UnionConverterToAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.CSharp73_partial-class#UnionConverterToAttribute.g.verified.cs new file mode 100644 index 0000000..28901ff --- /dev/null +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.CSharp73_partial-class#UnionConverterToAttribute.g.verified.cs @@ -0,0 +1,24 @@ +//HintName: UnionConverterToAttribute.g.cs +// +// This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes +// Feel free to open an issue +// +#if NETCOREAPP3_1_OR_GREATER +#nullable enable +#endif +using System; +using System.Runtime.CompilerServices; + +namespace N.SourceGenerators.UnionTypes +{ + [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, Inherited = false, AllowMultiple = true)] + sealed class UnionConverterToAttribute : Attribute + { + public Type ToType { get; } + + public UnionConverterToAttribute(Type toType) + { + ToType = toType; + } + } +} \ No newline at end of file diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.CSharp73_partial-class#UnionTypeAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.CSharp73_partial-class#UnionTypeAttribute.g.verified.cs new file mode 100644 index 0000000..927bc14 --- /dev/null +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.CSharp73_partial-class#UnionTypeAttribute.g.verified.cs @@ -0,0 +1,42 @@ +//HintName: UnionTypeAttribute.g.cs +// +// This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes +// Feel free to open an issue +// +#if NETCOREAPP3_1_OR_GREATER +#nullable enable +#endif +using System; +using System.Runtime.CompilerServices; + +namespace N.SourceGenerators.UnionTypes +{ + [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, Inherited = false, AllowMultiple = true)] + internal sealed class UnionTypeAttribute : Attribute + { + public Type Type { get; } +#if NETCOREAPP3_1_OR_GREATER + public string? Alias { get; } +#else + public string Alias { get; } +#endif + public int Order { get; } + public bool AllowNull { get; set; } +#if NETCOREAPP3_1_OR_GREATER + public object? TypeDiscriminator { get; set; } +#else + public object TypeDiscriminator { get; set; } +#endif + +#if NETCOREAPP3_1_OR_GREATER + public UnionTypeAttribute(Type type, string? alias = null, [CallerLineNumber] int order = 0) +#else + public UnionTypeAttribute(Type type, string alias = null, [CallerLineNumber] int order = 0) +#endif + { + Type = type; + Alias = alias; + Order = order; + } + } +} \ No newline at end of file diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.CSharp73_partial-struct#GenericUnionTypeAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.CSharp73_partial-struct#GenericUnionTypeAttribute.g.verified.cs new file mode 100644 index 0000000..17a28f9 --- /dev/null +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.CSharp73_partial-struct#GenericUnionTypeAttribute.g.verified.cs @@ -0,0 +1,27 @@ +//HintName: GenericUnionTypeAttribute.g.cs +// +// This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes +// Feel free to open an issue +// +#if NETCOREAPP3_1_OR_GREATER +#nullable enable +#endif +using System; +using System.Runtime.CompilerServices; + +namespace N.SourceGenerators.UnionTypes +{ + [AttributeUsage(AttributeTargets.GenericParameter, Inherited = false, AllowMultiple = false)] + internal sealed class GenericUnionTypeAttribute : Attribute + { +#if NETCOREAPP3_1_OR_GREATER + public string? Alias { get; set; } + public bool AllowNull { get; set; } + public object? TypeDiscriminator { get; set; } +#else + public string Alias { get; set; } + public bool AllowNull { get; set; } + public object TypeDiscriminator { get; set; } +#endif + } +} \ No newline at end of file diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.CSharp73_partial-struct#JsonPolymorphicUnionAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.CSharp73_partial-struct#JsonPolymorphicUnionAttribute.g.verified.cs new file mode 100644 index 0000000..ee781ad --- /dev/null +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.CSharp73_partial-struct#JsonPolymorphicUnionAttribute.g.verified.cs @@ -0,0 +1,23 @@ +//HintName: JsonPolymorphicUnionAttribute.g.cs +// +// This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes +// Feel free to open an issue +// +#if NETCOREAPP3_1_OR_GREATER +#nullable enable +#endif +using System; +using System.Runtime.CompilerServices; + +namespace N.SourceGenerators.UnionTypes +{ + [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] + internal sealed class JsonPolymorphicUnionAttribute : Attribute + { +#if NETCOREAPP3_1_OR_GREATER + public string? TypeDiscriminatorPropertyName { get; set; } +#else + public string TypeDiscriminatorPropertyName { get; set; } +#endif + } +} \ No newline at end of file diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.CSharp73_partial-struct#Result.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.CSharp73_partial-struct#Result.g.verified.cs new file mode 100644 index 0000000..b301b3c --- /dev/null +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.CSharp73_partial-struct#Result.g.verified.cs @@ -0,0 +1,435 @@ +//HintName: Result.g.cs +// +// This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes +// Feel free to open an issue +// +#pragma warning disable +namespace MyApp +{ + partial struct Result : System.IEquatable + { + private readonly int _variantId; + private const int SuccessId = 1; + private readonly global::MyApp.Success _success; + public bool IsSuccess => _variantId == SuccessId; + public global::MyApp.Success AsSuccess + { + get + { + if (_variantId == SuccessId) + return _success; + throw new System.InvalidOperationException($"Unable convert to Success. Inner value is {ValueAlias} not Success."); + } + } + + public Result(global::MyApp.Success success) + { + System.ArgumentNullException.ThrowIfNull(success); + _variantId = SuccessId; + _success = success; + _error = default(global::MyApp.Error); + _iReadOnlyListOfInt32 = default(global::System.Collections.Generic.IReadOnlyList); + _arrayOfString = default(string[]); + _tupleOfInt32AndString = default(global::System.Tuple); + } + + public static implicit operator Result(global::MyApp.Success success) => new Result(success); + public static explicit operator global::MyApp.Success(Result value) + { + if (value._variantId == SuccessId) + return value._success; + throw new System.InvalidOperationException($"Unable convert to Success. Inner value is {value.ValueAlias} not Success."); + } + + public bool TryGetSuccess([System.Diagnostics.CodeAnalysis.NotNullWhen(true)] out global::MyApp.Success value) + { + if (_variantId == SuccessId) + { + value = _success; + return true; + } + else + { + value = default; + return false; + } + } + + private const int ErrorId = 2; + private readonly global::MyApp.Error _error; + public bool IsError => _variantId == ErrorId; + public global::MyApp.Error AsError + { + get + { + if (_variantId == ErrorId) + return _error; + throw new System.InvalidOperationException($"Unable convert to Error. Inner value is {ValueAlias} not Error."); + } + } + + public Result(global::MyApp.Error @error) + { + System.ArgumentNullException.ThrowIfNull(@error); + _variantId = ErrorId; + _error = @error; + _success = default(global::MyApp.Success); + _iReadOnlyListOfInt32 = default(global::System.Collections.Generic.IReadOnlyList); + _arrayOfString = default(string[]); + _tupleOfInt32AndString = default(global::System.Tuple); + } + + public static implicit operator Result(global::MyApp.Error @error) => new Result(@error); + public static explicit operator global::MyApp.Error(Result value) + { + if (value._variantId == ErrorId) + return value._error; + throw new System.InvalidOperationException($"Unable convert to Error. Inner value is {value.ValueAlias} not Error."); + } + + public bool TryGetError([System.Diagnostics.CodeAnalysis.NotNullWhen(true)] out global::MyApp.Error value) + { + if (_variantId == ErrorId) + { + value = _error; + return true; + } + else + { + value = default; + return false; + } + } + + private const int IReadOnlyListOfInt32Id = 3; + private readonly global::System.Collections.Generic.IReadOnlyList _iReadOnlyListOfInt32; + public bool IsIReadOnlyListOfInt32 => _variantId == IReadOnlyListOfInt32Id; + public global::System.Collections.Generic.IReadOnlyList AsIReadOnlyListOfInt32 + { + get + { + if (_variantId == IReadOnlyListOfInt32Id) + return _iReadOnlyListOfInt32; + throw new System.InvalidOperationException($"Unable convert to IReadOnlyListOfInt32. Inner value is {ValueAlias} not IReadOnlyListOfInt32."); + } + } + + public Result(global::System.Collections.Generic.IReadOnlyList iReadOnlyListOfInt32) + { + System.ArgumentNullException.ThrowIfNull(iReadOnlyListOfInt32); + _variantId = IReadOnlyListOfInt32Id; + _iReadOnlyListOfInt32 = iReadOnlyListOfInt32; + _success = default(global::MyApp.Success); + _error = default(global::MyApp.Error); + _arrayOfString = default(string[]); + _tupleOfInt32AndString = default(global::System.Tuple); + } + + public bool TryGetIReadOnlyListOfInt32([System.Diagnostics.CodeAnalysis.NotNullWhen(true)] out global::System.Collections.Generic.IReadOnlyList value) + { + if (_variantId == IReadOnlyListOfInt32Id) + { + value = _iReadOnlyListOfInt32; + return true; + } + else + { + value = default; + return false; + } + } + + private const int ArrayOfStringId = 4; + private readonly string[] _arrayOfString; + public bool IsArrayOfString => _variantId == ArrayOfStringId; + public string[] AsArrayOfString + { + get + { + if (_variantId == ArrayOfStringId) + return _arrayOfString; + throw new System.InvalidOperationException($"Unable convert to ArrayOfString. Inner value is {ValueAlias} not ArrayOfString."); + } + } + + public Result(string[] arrayOfString) + { + System.ArgumentNullException.ThrowIfNull(arrayOfString); + _variantId = ArrayOfStringId; + _arrayOfString = arrayOfString; + _success = default(global::MyApp.Success); + _error = default(global::MyApp.Error); + _iReadOnlyListOfInt32 = default(global::System.Collections.Generic.IReadOnlyList); + _tupleOfInt32AndString = default(global::System.Tuple); + } + + public static implicit operator Result(string[] arrayOfString) => new Result(arrayOfString); + public static explicit operator string[](Result value) + { + if (value._variantId == ArrayOfStringId) + return value._arrayOfString; + throw new System.InvalidOperationException($"Unable convert to ArrayOfString. Inner value is {value.ValueAlias} not ArrayOfString."); + } + + public bool TryGetArrayOfString([System.Diagnostics.CodeAnalysis.NotNullWhen(true)] out string[] value) + { + if (_variantId == ArrayOfStringId) + { + value = _arrayOfString; + return true; + } + else + { + value = default; + return false; + } + } + + private const int TupleOfInt32AndStringId = 5; + private readonly global::System.Tuple _tupleOfInt32AndString; + public bool IsTupleOfInt32AndString => _variantId == TupleOfInt32AndStringId; + public global::System.Tuple AsTupleOfInt32AndString + { + get + { + if (_variantId == TupleOfInt32AndStringId) + return _tupleOfInt32AndString; + throw new System.InvalidOperationException($"Unable convert to TupleOfInt32AndString. Inner value is {ValueAlias} not TupleOfInt32AndString."); + } + } + + public Result(global::System.Tuple tupleOfInt32AndString) + { + System.ArgumentNullException.ThrowIfNull(tupleOfInt32AndString); + _variantId = TupleOfInt32AndStringId; + _tupleOfInt32AndString = tupleOfInt32AndString; + _success = default(global::MyApp.Success); + _error = default(global::MyApp.Error); + _iReadOnlyListOfInt32 = default(global::System.Collections.Generic.IReadOnlyList); + _arrayOfString = default(string[]); + } + + public static implicit operator Result(global::System.Tuple tupleOfInt32AndString) => new Result(tupleOfInt32AndString); + public static explicit operator global::System.Tuple(Result value) + { + if (value._variantId == TupleOfInt32AndStringId) + return value._tupleOfInt32AndString; + throw new System.InvalidOperationException($"Unable convert to TupleOfInt32AndString. Inner value is {value.ValueAlias} not TupleOfInt32AndString."); + } + + public bool TryGetTupleOfInt32AndString([System.Diagnostics.CodeAnalysis.NotNullWhen(true)] out global::System.Tuple value) + { + if (_variantId == TupleOfInt32AndStringId) + { + value = _tupleOfInt32AndString; + return true; + } + else + { + value = default; + return false; + } + } + + public TOut Match(global::System.Func matchSuccess, global::System.Func matchError, global::System.Func, TOut> matchIReadOnlyListOfInt32, global::System.Func matchArrayOfString, global::System.Func, TOut> matchTupleOfInt32AndString) + { + if (_variantId == SuccessId) + return matchSuccess(_success); + if (_variantId == ErrorId) + return matchError(_error); + if (_variantId == IReadOnlyListOfInt32Id) + return matchIReadOnlyListOfInt32(_iReadOnlyListOfInt32); + if (_variantId == ArrayOfStringId) + return matchArrayOfString(_arrayOfString); + if (_variantId == TupleOfInt32AndStringId) + return matchTupleOfInt32AndString(_tupleOfInt32AndString); + throw new System.InvalidOperationException("Inner type is unknown"); + } + + public async global::System.Threading.Tasks.Task MatchAsync(global::System.Func> matchSuccess, global::System.Func> matchError, global::System.Func, global::System.Threading.CancellationToken, global::System.Threading.Tasks.Task> matchIReadOnlyListOfInt32, global::System.Func> matchArrayOfString, global::System.Func, global::System.Threading.CancellationToken, global::System.Threading.Tasks.Task> matchTupleOfInt32AndString, global::System.Threading.CancellationToken ct) + { + if (_variantId == SuccessId) + return await matchSuccess(_success, ct).ConfigureAwait(false); + if (_variantId == ErrorId) + return await matchError(_error, ct).ConfigureAwait(false); + if (_variantId == IReadOnlyListOfInt32Id) + return await matchIReadOnlyListOfInt32(_iReadOnlyListOfInt32, ct).ConfigureAwait(false); + if (_variantId == ArrayOfStringId) + return await matchArrayOfString(_arrayOfString, ct).ConfigureAwait(false); + if (_variantId == TupleOfInt32AndStringId) + return await matchTupleOfInt32AndString(_tupleOfInt32AndString, ct).ConfigureAwait(false); + throw new System.InvalidOperationException("Inner type is unknown"); + } + + public void Switch(global::System.Action switchSuccess, global::System.Action switchError, global::System.Action> switchIReadOnlyListOfInt32, global::System.Action switchArrayOfString, global::System.Action> switchTupleOfInt32AndString) + { + if (_variantId == SuccessId) + { + switchSuccess(_success); + return; + } + + if (_variantId == ErrorId) + { + switchError(_error); + return; + } + + if (_variantId == IReadOnlyListOfInt32Id) + { + switchIReadOnlyListOfInt32(_iReadOnlyListOfInt32); + return; + } + + if (_variantId == ArrayOfStringId) + { + switchArrayOfString(_arrayOfString); + return; + } + + if (_variantId == TupleOfInt32AndStringId) + { + switchTupleOfInt32AndString(_tupleOfInt32AndString); + return; + } + + throw new System.InvalidOperationException("Inner type is unknown"); + } + + public async global::System.Threading.Tasks.Task SwitchAsync(global::System.Func switchSuccess, global::System.Func switchError, global::System.Func, global::System.Threading.CancellationToken, global::System.Threading.Tasks.Task> switchIReadOnlyListOfInt32, global::System.Func switchArrayOfString, global::System.Func, global::System.Threading.CancellationToken, global::System.Threading.Tasks.Task> switchTupleOfInt32AndString, global::System.Threading.CancellationToken ct) + { + if (_variantId == SuccessId) + { + await switchSuccess(_success, ct).ConfigureAwait(false); + return; + } + + if (_variantId == ErrorId) + { + await switchError(_error, ct).ConfigureAwait(false); + return; + } + + if (_variantId == IReadOnlyListOfInt32Id) + { + await switchIReadOnlyListOfInt32(_iReadOnlyListOfInt32, ct).ConfigureAwait(false); + return; + } + + if (_variantId == ArrayOfStringId) + { + await switchArrayOfString(_arrayOfString, ct).ConfigureAwait(false); + return; + } + + if (_variantId == TupleOfInt32AndStringId) + { + await switchTupleOfInt32AndString(_tupleOfInt32AndString, ct).ConfigureAwait(false); + return; + } + + throw new System.InvalidOperationException("Inner type is unknown"); + } + + public global::System.Type ValueType + { + get + { + if (_variantId == SuccessId) + return typeof(global::MyApp.Success); + if (_variantId == ErrorId) + return typeof(global::MyApp.Error); + if (_variantId == IReadOnlyListOfInt32Id) + return typeof(global::System.Collections.Generic.IReadOnlyList); + if (_variantId == ArrayOfStringId) + return typeof(string[]); + if (_variantId == TupleOfInt32AndStringId) + return typeof(global::System.Tuple); + throw new System.InvalidOperationException("Inner type is unknown"); + } + } + + private string ValueAlias + { + get + { + if (_variantId == SuccessId) + return "Success"; + if (_variantId == ErrorId) + return "Error"; + if (_variantId == IReadOnlyListOfInt32Id) + return "IReadOnlyListOfInt32"; + if (_variantId == ArrayOfStringId) + return "ArrayOfString"; + if (_variantId == TupleOfInt32AndStringId) + return "TupleOfInt32AndString"; + throw new System.InvalidOperationException("Inner type is unknown"); + } + } + + public override int GetHashCode() + { + if (_variantId == SuccessId) + return _success.GetHashCode(); + if (_variantId == ErrorId) + return _error.GetHashCode(); + if (_variantId == IReadOnlyListOfInt32Id) + return _iReadOnlyListOfInt32.GetHashCode(); + if (_variantId == ArrayOfStringId) + return _arrayOfString.GetHashCode(); + if (_variantId == TupleOfInt32AndStringId) + return _tupleOfInt32AndString.GetHashCode(); + throw new System.InvalidOperationException("Inner type is unknown"); + } + + public static bool operator ==(Result left, Result right) + { + return left.Equals(right); + } + + public static bool operator !=(Result left, Result right) + { + return !left.Equals(right); + } + + public bool Equals(Result other) + { + if (ValueType != other.ValueType) + { + return false; + } + + if (_variantId == SuccessId) + return System.Collections.Generic.EqualityComparer.Default.Equals(_success, other._success); + if (_variantId == ErrorId) + return System.Collections.Generic.EqualityComparer.Default.Equals(_error, other._error); + if (_variantId == IReadOnlyListOfInt32Id) + return System.Collections.Generic.EqualityComparer>.Default.Equals(_iReadOnlyListOfInt32, other._iReadOnlyListOfInt32); + if (_variantId == ArrayOfStringId) + return System.Collections.Generic.EqualityComparer.Default.Equals(_arrayOfString, other._arrayOfString); + if (_variantId == TupleOfInt32AndStringId) + return System.Collections.Generic.EqualityComparer>.Default.Equals(_tupleOfInt32AndString, other._tupleOfInt32AndString); + throw new System.InvalidOperationException("Inner type is unknown"); + } + + public override string ToString() + { + if (_variantId == SuccessId) + return _success.ToString(); + if (_variantId == ErrorId) + return _error.ToString(); + if (_variantId == IReadOnlyListOfInt32Id) + return _iReadOnlyListOfInt32.ToString(); + if (_variantId == ArrayOfStringId) + return _arrayOfString.ToString(); + if (_variantId == TupleOfInt32AndStringId) + return _tupleOfInt32AndString.ToString(); + throw new System.InvalidOperationException("Inner type is unknown"); + } + + public override bool Equals(object obj) + { + return obj is Result other && Equals(other); + } + } +} \ No newline at end of file diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.CSharp73_partial-struct#UnionConverterAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.CSharp73_partial-struct#UnionConverterAttribute.g.verified.cs new file mode 100644 index 0000000..973b6e2 --- /dev/null +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.CSharp73_partial-struct#UnionConverterAttribute.g.verified.cs @@ -0,0 +1,32 @@ +//HintName: UnionConverterAttribute.g.cs +#if NETCOREAPP3_1_OR_GREATER +#nullable enable +#endif +using System; +using System.Runtime.CompilerServices; + +namespace N.SourceGenerators.UnionTypes +{ + [AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = true)] + sealed class UnionConverterAttribute : Attribute + { + public Type FromType { get; } + public Type ToType { get; } +#if NETCOREAPP3_1_OR_GREATER + public string? MethodName { get; } +#else + public string MethodName { get; } +#endif + +#if NETCOREAPP3_1_OR_GREATER + public UnionConverterAttribute(Type fromType, Type toType, string? methodName = null) +#else + public UnionConverterAttribute(Type fromType, Type toType, string methodName = null) +#endif + { + FromType = fromType; + ToType = toType; + MethodName = methodName; + } + } +} \ No newline at end of file diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.CSharp73_partial-struct#UnionConverterFromAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.CSharp73_partial-struct#UnionConverterFromAttribute.g.verified.cs new file mode 100644 index 0000000..222e936 --- /dev/null +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.CSharp73_partial-struct#UnionConverterFromAttribute.g.verified.cs @@ -0,0 +1,24 @@ +//HintName: UnionConverterFromAttribute.g.cs +// +// This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes +// Feel free to open an issue +// +#if NETCOREAPP3_1_OR_GREATER +#nullable enable +#endif +using System; +using System.Runtime.CompilerServices; + +namespace N.SourceGenerators.UnionTypes +{ + [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, Inherited = false, AllowMultiple = true)] + sealed class UnionConverterFromAttribute : Attribute + { + public Type FromType { get; } + + public UnionConverterFromAttribute(Type fromType) + { + FromType = fromType; + } + } +} \ No newline at end of file diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.CSharp73_partial-struct#UnionConverterToAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.CSharp73_partial-struct#UnionConverterToAttribute.g.verified.cs new file mode 100644 index 0000000..28901ff --- /dev/null +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.CSharp73_partial-struct#UnionConverterToAttribute.g.verified.cs @@ -0,0 +1,24 @@ +//HintName: UnionConverterToAttribute.g.cs +// +// This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes +// Feel free to open an issue +// +#if NETCOREAPP3_1_OR_GREATER +#nullable enable +#endif +using System; +using System.Runtime.CompilerServices; + +namespace N.SourceGenerators.UnionTypes +{ + [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, Inherited = false, AllowMultiple = true)] + sealed class UnionConverterToAttribute : Attribute + { + public Type ToType { get; } + + public UnionConverterToAttribute(Type toType) + { + ToType = toType; + } + } +} \ No newline at end of file diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.CSharp73_partial-struct#UnionTypeAttribute.g.verified.cs b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.CSharp73_partial-struct#UnionTypeAttribute.g.verified.cs new file mode 100644 index 0000000..927bc14 --- /dev/null +++ b/tests/N.SourceGenerators.UnionTypes.Tests/Snapshots/GeneratorTests.CSharp73_partial-struct#UnionTypeAttribute.g.verified.cs @@ -0,0 +1,42 @@ +//HintName: UnionTypeAttribute.g.cs +// +// This code was generated by https://github.com/Ne4to/N.SourceGenerators.UnionTypes +// Feel free to open an issue +// +#if NETCOREAPP3_1_OR_GREATER +#nullable enable +#endif +using System; +using System.Runtime.CompilerServices; + +namespace N.SourceGenerators.UnionTypes +{ + [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, Inherited = false, AllowMultiple = true)] + internal sealed class UnionTypeAttribute : Attribute + { + public Type Type { get; } +#if NETCOREAPP3_1_OR_GREATER + public string? Alias { get; } +#else + public string Alias { get; } +#endif + public int Order { get; } + public bool AllowNull { get; set; } +#if NETCOREAPP3_1_OR_GREATER + public object? TypeDiscriminator { get; set; } +#else + public object TypeDiscriminator { get; set; } +#endif + +#if NETCOREAPP3_1_OR_GREATER + public UnionTypeAttribute(Type type, string? alias = null, [CallerLineNumber] int order = 0) +#else + public UnionTypeAttribute(Type type, string alias = null, [CallerLineNumber] int order = 0) +#endif + { + Type = type; + Alias = alias; + Order = order; + } + } +} \ No newline at end of file diff --git a/tests/N.SourceGenerators.UnionTypes.Tests/TestHelper.cs b/tests/N.SourceGenerators.UnionTypes.Tests/TestHelper.cs index 6126649..83cd2eb 100644 --- a/tests/N.SourceGenerators.UnionTypes.Tests/TestHelper.cs +++ b/tests/N.SourceGenerators.UnionTypes.Tests/TestHelper.cs @@ -1,7 +1,6 @@ // Ported from https://andrewlock.net/creating-a-source-generator-part-2-testing-an-incremental-generator-with-snapshot-testing/ using System.Collections.Immutable; -using System.Reflection; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; @@ -12,15 +11,21 @@ public static class TestHelper { public static Task Verify( string source, + LanguageVersion languageVersion = LanguageVersion.Latest, string? parametersText = null, params PortableExecutableReference[] additionalReferences) where TGenerator : IIncrementalGenerator, new() { - return Verify(new[] { source }, parametersText, additionalReferences); + return Verify( + [source], + languageVersion, + parametersText, + additionalReferences); } public static async Task Verify( string[] sources, + LanguageVersion languageVersion = LanguageVersion.Latest, string? parametersText = null, params PortableExecutableReference[] additionalReferences) where TGenerator : IIncrementalGenerator, new() @@ -31,7 +36,8 @@ public static async Task Verify( { string source = sources[sourceIndex]; // Parse the provided string into a C# syntax tree - SyntaxTree syntaxTree = CSharpSyntaxTree.ParseText(source); + var options = CSharpParseOptions.Default.WithLanguageVersion(languageVersion); + SyntaxTree syntaxTree = CSharpSyntaxTree.ParseText(source, options); // Create references for assemblies we require // We could add multiple references if required var references = new List @@ -43,11 +49,13 @@ public static async Task Verify( // /usr/local/share/dotnet/shared/Microsoft.NETCore.App/7.0.11/System.Text.Json.dll // Create a Roslyn compilation for the syntax tree. + CSharpCompilationOptions compilationOptions = new(OutputKind.DynamicallyLinkedLibrary); + CSharpCompilation compilation = CSharpCompilation.Create( assemblyName: $"Tests{sourceIndex}", syntaxTrees: new[] { syntaxTree }, references, - new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary)); + compilationOptions); if (previousCompilation != null) { @@ -58,7 +66,7 @@ public static async Task Verify( var generator = new TGenerator(); // The GeneratorDriver is used to run our generator against a compilation - GeneratorDriver driver = CSharpGeneratorDriver.Create(generator); + GeneratorDriver driver = CSharpGeneratorDriver.Create(parseOptions: options, generators: [generator.AsSourceGenerator()]); // Run the source generator! driver = driver.RunGeneratorsAndUpdateCompilation(compilation, out var outputCompilation,