private double DoGetXUnitValue(double?totalValue, XGraphicsUnit type) { XUnit value; switch (Unit) { case EUnit.Millimeter: value = new XUnit(Value, XGraphicsUnit.Millimeter); break; case EUnit.Centimeter: value = new XUnit(Value, XGraphicsUnit.Centimeter); break; case EUnit.Inch: value = new XUnit(Value, XGraphicsUnit.Inch); break; case EUnit.Percentage: if (totalValue == null) { throw new InvalidOperationException("When unit type percentage is used, the totalValue needs to be provided."); } //Calculate the actual value, using provided total value value = Value / 100 * totalValue.Value; break; case EUnit.Point: value = Value; break; default: throw new InvalidOperationException(string.Format("Unknown unit {0}", Unit)); } value.ConvertType(type); return(value.Value); }