private double Conversion(string MeasurementType, string conversionType, double value) { Length length = new Length(); Weights weights = new Weights(); Volumes volume = new Volumes(); Temperature temperature = new Temperature(); if (MeasurementType == "length") { LengthUnit unit = length.SetUnitAndConvertLength(conversionType); if (unit == LengthUnit.FeetToInch || unit == LengthUnit.YardToInch || unit == LengthUnit.CentimeterToInch) { return(length.ConvertLength(unit, value)); } } if (MeasurementType == "weight") { WeightsUnit unit = weights.SetUnitAndConvertWeights(conversionType); if (unit.Equals(WeightsUnit.KilogramToGrams) || unit.Equals(WeightsUnit.TonneToKilograms)) { return(weights.ConvertWeigths(unit, value)); } } if (MeasurementType == "volume") { VolumeUnit unit = volume.SetUnitAndConvertVolume(conversionType); if (unit.Equals(VolumeUnit.GallonToLiter) || unit.Equals(VolumeUnit.LiterToMilliliter) || unit.Equals(VolumeUnit.MilliliterToLiter)) { return(volume.ConvertVolumes(unit, value)); } } if (MeasurementType == "temperature") { TemperatureUnit unit = temperature.SetUnitAndConvertTemperature(conversionType); if (unit.Equals(TemperatureUnit.CelsiusToFahrenheit)) { return(temperature.ConvertTemperature(unit, value)); } } return(value); }
/// <summary> /// Method to convert one volume to another /// </summary> /// <param name="unit">defines which unit used</param> /// <param name="weights">weights for conversion</param> /// <returns>returns value after calculation</returns> public double ConvertWeigths(WeightsUnit unit, double weights) { try { if (unit.Equals(WeightsUnit.KilogramToGrams) || unit.Equals(WeightsUnit.TonneToKilograms)) { return(weights * CommanWeights); } return(weights); } catch (QuantityException e) { throw new QuantityException(QuantityException.ExceptionType.InvalidData, e.Message); } catch (Exception e) { throw e; } }