@@ -15,7 +15,9 @@ public partial class UnionTypesGenerator
1515
1616 private const string UnionTypeAttributeText = $$ """
1717 {{ AutoGeneratedComment }}
18+ #if NETCOREAPP3_1_OR_GREATER
1819 #nullable enable
20+ #endif
1921 using System;
2022 using System.Runtime.CompilerServices;
2123
@@ -25,12 +27,24 @@ namespace N.SourceGenerators.UnionTypes
2527 internal sealed class UnionTypeAttribute : Attribute
2628 {
2729 public Type Type { get; }
30+ #if NETCOREAPP3_1_OR_GREATER
2831 public string? Alias { get; }
32+ #else
33+ public string Alias { get; }
34+ #endif
2935 public int Order { get; }
3036 public bool AllowNull { get; set; }
37+ #if NETCOREAPP3_1_OR_GREATER
3138 public object? TypeDiscriminator { get; set; }
32-
39+ #else
40+ public object TypeDiscriminator { get; set; }
41+ #endif
42+
43+ #if NETCOREAPP3_1_OR_GREATER
3344 public UnionTypeAttribute(Type type, string? alias = null, [CallerLineNumber] int order = 0)
45+ #else
46+ public UnionTypeAttribute(Type type, string alias = null, [CallerLineNumber] int order = 0)
47+ #endif
3448 {
3549 Type = type;
3650 Alias = alias;
@@ -42,7 +56,9 @@ public UnionTypeAttribute(Type type, string? alias = null, [CallerLineNumber] in
4256
4357 private const string GenericUnionTypeAttributeText = $$ """
4458 {{ AutoGeneratedComment }}
59+ #if NETCOREAPP3_1_OR_GREATER
4560 #nullable enable
61+ #endif
4662 using System;
4763 using System.Runtime.CompilerServices;
4864
@@ -51,16 +67,24 @@ namespace N.SourceGenerators.UnionTypes
5167 [AttributeUsage(AttributeTargets.GenericParameter, Inherited = false, AllowMultiple = false)]
5268 internal sealed class GenericUnionTypeAttribute : Attribute
5369 {
70+ #if NETCOREAPP3_1_OR_GREATER
5471 public string? Alias { get; set; }
5572 public bool AllowNull { get; set; }
5673 public object? TypeDiscriminator { get; set; }
74+ #else
75+ public string Alias { get; set; }
76+ public bool AllowNull { get; set; }
77+ public object TypeDiscriminator { get; set; }
78+ #endif
5779 }
5880 }
5981 """ ;
6082
6183 private const string JsonPolymorphicUnionAttributeText = $$ """
6284 {{ AutoGeneratedComment }}
85+ #if NETCOREAPP3_1_OR_GREATER
6386 #nullable enable
87+ #endif
6488 using System;
6589 using System.Runtime.CompilerServices;
6690
@@ -69,14 +93,20 @@ namespace N.SourceGenerators.UnionTypes
6993 [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, Inherited = false, AllowMultiple = false)]
7094 internal sealed class JsonPolymorphicUnionAttribute : Attribute
7195 {
96+ #if NETCOREAPP3_1_OR_GREATER
7297 public string? TypeDiscriminatorPropertyName { get; set; }
98+ #else
99+ public string TypeDiscriminatorPropertyName { get; set; }
100+ #endif
73101 }
74102 }
75103 """ ;
76104
77105 private const string UnionConverterFromAttributeText = $$ """
78106 {{ AutoGeneratedComment }}
107+ #if NETCOREAPP3_1_OR_GREATER
79108 #nullable enable
109+ #endif
80110 using System;
81111 using System.Runtime.CompilerServices;
82112
@@ -97,7 +127,9 @@ public UnionConverterFromAttribute(Type fromType)
97127
98128 private const string UnionConverterToAttributeText = $$ """
99129 {{ AutoGeneratedComment }}
130+ #if NETCOREAPP3_1_OR_GREATER
100131 #nullable enable
132+ #endif
101133 using System;
102134 using System.Runtime.CompilerServices;
103135
@@ -117,7 +149,9 @@ public UnionConverterToAttribute(Type toType)
117149 """ ;
118150
119151 private const string UnionConverterAttributeText = """
152+ #if NETCOREAPP3_1_OR_GREATER
120153 #nullable enable
154+ #endif
121155 using System;
122156 using System.Runtime.CompilerServices;
123157
@@ -128,9 +162,17 @@ sealed class UnionConverterAttribute : Attribute
128162 {
129163 public Type FromType { get; }
130164 public Type ToType { get; }
165+ #if NETCOREAPP3_1_OR_GREATER
131166 public string? MethodName { get; }
167+ #else
168+ public string MethodName { get; }
169+ #endif
132170
171+ #if NETCOREAPP3_1_OR_GREATER
133172 public UnionConverterAttribute(Type fromType, Type toType, string? methodName = null)
173+ #else
174+ public UnionConverterAttribute(Type fromType, Type toType, string methodName = null)
175+ #endif
134176 {
135177 FromType = fromType;
136178 ToType = toType;
0 commit comments