Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace Appegy.Union.Generator.Shapes;
public interface IShape
{
double Area { get; }
void LogArea();
}

[Union(typeof(Circle), typeof(Rectangle), typeof(Hexagon))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ public readonly struct Circle(double radius) : IShape, IEquatable<Circle>

public double Area => Math.PI * Radius * Radius;

public void LogArea()
{
Console.WriteLine($"{nameof(Circle)} area: {Area}");
}

public override string ToString()
{
return nameof(Circle);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ public readonly struct Hexagon(double sideLength) : IShape, IEquatable<Hexagon>

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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}\");");
Expand Down