Refactored UnionObject to primarily just use BlockStatementObject for string construction

This commit is contained in:
Mike Smith 2016-02-07 21:17:43 -08:00
parent efc981579f
commit a34992bfaa
3 changed files with 40 additions and 18 deletions

View File

@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OSCADSharp
{
/// <summary>
/// A statement that has multiple child nodes, whose ToString output
/// is more or less just an aggregate of the children
/// </summary>
internal class BlockStatementObject : OSCADObject
{
private string outerStatement;
private IEnumerable<OSCADObject> children;
internal BlockStatementObject(string outerStatement, IEnumerable<OSCADObject> children)
{
this.outerStatement = outerStatement;
this.children = children;
}
public override string ToString()
{
StringBuilder sb = new StringBuilder();
foreach (var child in this.children)
{
sb.AppendLine(child.ToString());
}
var formatter = new BlockFormatter(this.outerStatement, sb.ToString());
return formatter.ToString();
}
}
}

View File

@ -9,30 +9,14 @@ namespace OSCADSharp.Booleans
/// <summary>
/// A union of child nodes. This is the sum of all children (logical or).
/// </summary>
internal class Union : OSCADObject
internal class Union : BlockStatementObject
{
private IEnumerable<OSCADObject> children;
/// <summary>
/// Create a union that is the combination of all children
/// </summary>
/// <param name="children">OSCADObjects to combine</param>
internal Union(IEnumerable<OSCADObject> children)
internal Union(IEnumerable<OSCADObject> children) : base("union()", children)
{
this.children = children;
}
public override string ToString()
{
string unionCommand = "union()";
StringBuilder sb = new StringBuilder();
foreach (var child in this.children)
{
sb.AppendLine(child.ToString());
}
var formatter = new BlockFormatter(unionCommand, sb.ToString());
return formatter.ToString();
}
}
}

View File

@ -41,6 +41,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="BlockFormatter.cs" />
<Compile Include="BlockStatementObject.cs" />
<Compile Include="Booleans\Union.cs" />
<Compile Include="OSCADObject.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />