Replaced a bunch of conditionals with new method BindIfVariableNotNull

This commit is contained in:
Michael Smith 2016-03-03 21:27:56 -08:00
parent 730b54d703
commit 4c51ffc3f4
8 changed files with 31 additions and 43 deletions

View File

@ -767,6 +767,17 @@ namespace OSCADSharp
/// </summary>
internal OSCADObject Parent { get; set; }
/// <summary>
/// If the variable is not null, binds it to the property specified
/// </summary>
/// <param name="property"></param>
/// <param name="variable"></param>
internal void BindIfVariableNotNull(string property, Variable variable)
{
if (variable != null)
this.Bind(property, variable);
}
/// <summary>
/// Internal collection of children for this object
/// </summary>

View File

@ -75,14 +75,10 @@ namespace OSCADSharp.Solids
/// <param name="minimumFragmentSize"></param>
public Sphere(Variable diameter = null, Variable resolution = null, Variable minimumAngle = null, Variable minimumFragmentSize = null)
{
if (diameter != null)
this.Bind("diameter", diameter);
if (resolution != null)
this.Bind("resolution", resolution);
if (minimumAngle != null)
this.Bind("minimumangle", minimumAngle);
if (minimumFragmentSize != null)
this.Bind("minimumfragmentsize", minimumFragmentSize);
this.BindIfVariableNotNull("diameter", diameter);
this.BindIfVariableNotNull("resolution", resolution);
this.BindIfVariableNotNull("minimumangle", minimumAngle);
this.BindIfVariableNotNull("minimumfragmentsize", minimumFragmentSize);
}
#endregion

View File

@ -39,10 +39,7 @@ namespace OSCADSharp.Transforms
internal ColoredObject(OSCADObject obj, Variable colorName, Variable opacity) : base(obj)
{
this.Bind("color", colorName);
if(opacity != null)
{
this.Bind("opacity", opacity);
}
this.BindIfVariableNotNull("opacity", opacity);
}
public override string ToString()

View File

@ -38,13 +38,9 @@ namespace OSCADSharp.Transforms
internal MirroredObject(OSCADObject obj, Vector3 normal, Variable x, Variable y, Variable z) : base(obj)
{
this.Normal = new BindableVector(normal);
if (x != null)
this.Bind("x", x);
if (y != null)
this.Bind("y", y);
if (z != null)
this.Bind("z", z);
this.BindIfVariableNotNull("x", x);
this.BindIfVariableNotNull("y", y);
this.BindIfVariableNotNull("z", z);
}
public override string ToString()

View File

@ -38,12 +38,9 @@ namespace OSCADSharp.Transforms
{
this.Size = new BindableVector(size);
if (x != null)
this.Bind("x", x);
if (y != null)
this.Bind("y", y);
if (z != null)
this.Bind("z", z);
this.BindIfVariableNotNull("x", x);
this.BindIfVariableNotNull("y", y);
this.BindIfVariableNotNull("z", z);
}
public override string ToString()

View File

@ -38,12 +38,9 @@ namespace OSCADSharp.Transforms
{
this.Angle = new BindableVector(angle);
if (x != null)
this.Bind("x", x);
if (y != null)
this.Bind("y", y);
if (z != null)
this.Bind("z", z);
this.BindIfVariableNotNull("x", x);
this.BindIfVariableNotNull("y", y);
this.BindIfVariableNotNull("z", z);
}
public override string ToString()

View File

@ -38,12 +38,9 @@ namespace OSCADSharp.Transforms
{
this.ScaleFactor = new BindableVector(scale);
if (x != null)
this.Bind("x", x);
if (y != null)
this.Bind("y", y);
if (z != null)
this.Bind("z", z);
this.BindIfVariableNotNull("x", x);
this.BindIfVariableNotNull("y", y);
this.BindIfVariableNotNull("z", z);
}
public override string ToString()

View File

@ -35,12 +35,9 @@ namespace OSCADSharp.Transforms
{
this.Vector = new BindableVector(vector);
if (x != null)
this.Bind("x", x);
if (y != null)
this.Bind("y", y);
if (z != null)
this.Bind("z", z);
this.BindIfVariableNotNull("x", x);
this.BindIfVariableNotNull("y", y);
this.BindIfVariableNotNull("z", z);
}
public override string ToString()