From 2c7a7ee1d597aec56f320cb9bf1c02a119670fcd Mon Sep 17 00:00:00 2001 From: Temo Nikolaishvili Date: Fri, 16 May 2025 11:15:48 +0400 Subject: [PATCH] minor change also added ChoiceTypePropertyAttribute that will be automatically added to ChoiceOf property --- Directory.Build.props | 2 +- src/AltaSoft.Choice.Generator/Executor.cs | 1 + src/AltaSoft.Choice/ChoiceTypePropertyAttribute.cs | 10 ++++++++++ ...CompileCorrectly#Authorisation1Choice.g.verified.cs | 1 + ...CompileCorrectly#Authorisation1Choice.g.verified.cs | 1 + 5 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 src/AltaSoft.Choice/ChoiceTypePropertyAttribute.cs diff --git a/Directory.Build.props b/Directory.Build.props index 41e8f40..88a2b30 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -9,7 +9,7 @@ Choice generator ALTA Software llc. Copyright © 2024 ALTA Software llc. - 1.3.0 + 1.3.1 diff --git a/src/AltaSoft.Choice.Generator/Executor.cs b/src/AltaSoft.Choice.Generator/Executor.cs index 4ec1948..6c60c25 100644 --- a/src/AltaSoft.Choice.Generator/Executor.cs +++ b/src/AltaSoft.Choice.Generator/Executor.cs @@ -90,6 +90,7 @@ private static SourceCodeBuilder Process(INamedTypeSymbol typeSymbol, ListChoice enum "); sb.AppendLine("[JsonIgnore]"); sb.AppendLine("[XmlIgnore]"); + sb.AppendLine("[ChoiceTypeProperty]"); sb.AppendLine("public ChoiceOf ChoiceType { get; private set; }"); sb.NewLine(); diff --git a/src/AltaSoft.Choice/ChoiceTypePropertyAttribute.cs b/src/AltaSoft.Choice/ChoiceTypePropertyAttribute.cs new file mode 100644 index 0000000..47024aa --- /dev/null +++ b/src/AltaSoft.Choice/ChoiceTypePropertyAttribute.cs @@ -0,0 +1,10 @@ +using System; + +namespace AltaSoft.Choice +{ + /// + /// Represents the attribute used to mark a property as a choice type property. + /// + [AttributeUsage(AttributeTargets.Property)] + public sealed class ChoiceTypePropertyAttribute : Attribute; +} diff --git a/tests/AltaSoft.Choice.Generator.SnapshotTests/Snapshots/ChoiceGeneratorTest.ChoiceTypeShouldGenerateAllMethodsAndCompileCorrectly#Authorisation1Choice.g.verified.cs b/tests/AltaSoft.Choice.Generator.SnapshotTests/Snapshots/ChoiceGeneratorTest.ChoiceTypeShouldGenerateAllMethodsAndCompileCorrectly#Authorisation1Choice.g.verified.cs index 758cb24..17187d4 100644 --- a/tests/AltaSoft.Choice.Generator.SnapshotTests/Snapshots/ChoiceGeneratorTest.ChoiceTypeShouldGenerateAllMethodsAndCompileCorrectly#Authorisation1Choice.g.verified.cs +++ b/tests/AltaSoft.Choice.Generator.SnapshotTests/Snapshots/ChoiceGeneratorTest.ChoiceTypeShouldGenerateAllMethodsAndCompileCorrectly#Authorisation1Choice.g.verified.cs @@ -40,6 +40,7 @@ public Authorisation1Choice() /// [JsonIgnore] [XmlIgnore] + [ChoiceTypeProperty] public ChoiceOf ChoiceType { get; private set; } private TestNamespace.OtherNamespace.Authorisation1Code? _code; diff --git a/tests/AltaSoft.Choice.Generator.SnapshotTests/Snapshots/ChoiceGeneratorTest.ChoiceTypeShouldNotGenerateImplicitMethodsAndCompileCorrectly#Authorisation1Choice.g.verified.cs b/tests/AltaSoft.Choice.Generator.SnapshotTests/Snapshots/ChoiceGeneratorTest.ChoiceTypeShouldNotGenerateImplicitMethodsAndCompileCorrectly#Authorisation1Choice.g.verified.cs index a943f9a..0e1b9af 100644 --- a/tests/AltaSoft.Choice.Generator.SnapshotTests/Snapshots/ChoiceGeneratorTest.ChoiceTypeShouldNotGenerateImplicitMethodsAndCompileCorrectly#Authorisation1Choice.g.verified.cs +++ b/tests/AltaSoft.Choice.Generator.SnapshotTests/Snapshots/ChoiceGeneratorTest.ChoiceTypeShouldNotGenerateImplicitMethodsAndCompileCorrectly#Authorisation1Choice.g.verified.cs @@ -40,6 +40,7 @@ public Authorisation1Choice() /// [JsonIgnore] [XmlIgnore] + [ChoiceTypeProperty] public ChoiceOf ChoiceType { get; private set; } private string? _code;