private string GetResult(double value, Unit unit, Unit toUnit) { var sb = new StringBuilder(); foreach (var conversion in Units.Conversions) { if (conversion.From == unit && conversion.To == toUnit) { var result = GetResult(value, conversion); sb.Append(result); } } if (sb.Length == 0) { Conversion first = null; Conversion second = null; // no direct conversion, try 2-step chain foreach (var conversion in Units.Conversions) { if (conversion.From == unit) { first = conversion; } if (conversion.To == toUnit) { second = conversion; } } if (first != null && second != null && first.To == second.From) { var composite = new Conversion(first.From, second.To, v => second.Converter(first.Converter(v))); sb.Append(GetResult(value, composite)); } } return(sb.ToString()); }
private string GetResult(double value, Conversion conversion) { return(Div($"{value} {conversion.From.ToString()} = {conversion.Converter(value)} {conversion.To.ToString()}")); }
private string GetResult(double value, Conversion conversion) { return Div($"{value} {conversion.From.ToString()} = {conversion.Converter(value)} {conversion.To.ToString()}"); }