From 290aae577940b880db20b0c45501a60ca6297db8 Mon Sep 17 00:00:00 2001 From: Ivan Murashka Date: Thu, 12 Feb 2026 18:13:25 +0100 Subject: [PATCH] fix void method for Expose attributes --- .../Appegy.Union.Generator.Shapes/Shapes/Shape.cs | 1 + .../Shapes/Variants/Circle.cs | 5 +++++ .../Shapes/Variants/Hexagon.cs | 5 +++++ .../Shapes/Variants/Rectangle.cs | 5 +++++ .../Expose/Implementations/ImplementMethods.cs | 9 ++++++++- 5 files changed, 24 insertions(+), 1 deletion(-) diff --git a/Appegy.Union.Generator~/Appegy.Union.Generator.Shapes/Shapes/Shape.cs b/Appegy.Union.Generator~/Appegy.Union.Generator.Shapes/Shapes/Shape.cs index cb510cb..2b45705 100644 --- a/Appegy.Union.Generator~/Appegy.Union.Generator.Shapes/Shapes/Shape.cs +++ b/Appegy.Union.Generator~/Appegy.Union.Generator.Shapes/Shapes/Shape.cs @@ -5,6 +5,7 @@ namespace Appegy.Union.Generator.Shapes; public interface IShape { double Area { get; } + void LogArea(); } [Union(typeof(Circle), typeof(Rectangle), typeof(Hexagon))] diff --git a/Appegy.Union.Generator~/Appegy.Union.Generator.Shapes/Shapes/Variants/Circle.cs b/Appegy.Union.Generator~/Appegy.Union.Generator.Shapes/Shapes/Variants/Circle.cs index 9a10751..ef1d795 100644 --- a/Appegy.Union.Generator~/Appegy.Union.Generator.Shapes/Shapes/Variants/Circle.cs +++ b/Appegy.Union.Generator~/Appegy.Union.Generator.Shapes/Shapes/Variants/Circle.cs @@ -8,6 +8,11 @@ public readonly struct Circle(double radius) : IShape, IEquatable public double Area => Math.PI * Radius * Radius; + public void LogArea() + { + Console.WriteLine($"{nameof(Circle)} area: {Area}"); + } + public override string ToString() { return nameof(Circle); diff --git a/Appegy.Union.Generator~/Appegy.Union.Generator.Shapes/Shapes/Variants/Hexagon.cs b/Appegy.Union.Generator~/Appegy.Union.Generator.Shapes/Shapes/Variants/Hexagon.cs index c5a02fe..603ad51 100644 --- a/Appegy.Union.Generator~/Appegy.Union.Generator.Shapes/Shapes/Variants/Hexagon.cs +++ b/Appegy.Union.Generator~/Appegy.Union.Generator.Shapes/Shapes/Variants/Hexagon.cs @@ -8,6 +8,11 @@ public readonly struct Hexagon(double sideLength) : IShape, IEquatable public double Area => 3 * Math.Sqrt(3) * SideLength * SideLength / 2; + public void LogArea() + { + Console.WriteLine($"{nameof(Hexagon)} area: {Area}"); + } + public override string ToString() { return nameof(Hexagon); diff --git a/Appegy.Union.Generator~/Appegy.Union.Generator.Shapes/Shapes/Variants/Rectangle.cs b/Appegy.Union.Generator~/Appegy.Union.Generator.Shapes/Shapes/Variants/Rectangle.cs index e747b6e..c418977 100644 --- a/Appegy.Union.Generator~/Appegy.Union.Generator.Shapes/Shapes/Variants/Rectangle.cs +++ b/Appegy.Union.Generator~/Appegy.Union.Generator.Shapes/Shapes/Variants/Rectangle.cs @@ -8,6 +8,11 @@ public readonly struct Rectangle(double width, double height) : IShape, IEquatab public double Height { get; } = height; public double Area => Width * Height; + public void LogArea() + { + Console.WriteLine($"{nameof(Rectangle)} area: {Area}"); + } + public override string ToString() { return nameof(Rectangle); diff --git a/Appegy.Union.Generator~/Appegy.Union.Generator/Expose/Implementations/ImplementMethods.cs b/Appegy.Union.Generator~/Appegy.Union.Generator/Expose/Implementations/ImplementMethods.cs index 1f38d71..f409b9d 100644 --- a/Appegy.Union.Generator~/Appegy.Union.Generator/Expose/Implementations/ImplementMethods.cs +++ b/Appegy.Union.Generator~/Appegy.Union.Generator/Expose/Implementations/ImplementMethods.cs @@ -165,7 +165,14 @@ private static void GenerateMethodBody(IndentedTextWriter codeWriter, IMethodSym codeWriter.Write("("); GenerateMethodArguments(codeWriter, methodSymbol); - codeWriter.WriteLine(");"); + codeWriter.Write(");"); + + if (methodSymbol.ReturnsVoid) + { + codeWriter.Write(" break;"); + } + + codeWriter.WriteLine(); } codeWriter.WriteLine("default: throw new global::System.InvalidOperationException($\"Unknown type of union: {_type}\");");