public Task <Result> Execute(CommandMetadata metadata, double value, string from) { Converter fromConverter = ParentPlugin.FindConverter(from); if (fromConverter != null) { Converter toConverter = ParentPlugin.FindRandomOfType(fromConverter.Type, fromConverter); return(Execute(metadata, value, from, toConverter.Name)); // don't question it. } else { throw new InvalidOperationException("Cannot convert from unit type " + from); } }
public Task <Result> Execute(CommandMetadata metadata, double value, string from, string to) { Converter fromConverter = ParentPlugin.FindConverter(from); Converter toConverter = ParentPlugin.FindConverter(to); if (fromConverter != null && toConverter != null) { value = toConverter.FromSI(toConverter.ToSI(value)); return(TaskResult(value, ParentPlugin.GetConversionString(value, fromConverter, toConverter))); } else if (fromConverter == null) { throw new InvalidOperationException("Cannot convert from unit type " + from); } else if (toConverter == null) { throw new InvalidOperationException("Cannot convert to unit type " + to); } else { throw new InvalidOperationException("You shouldn't be able to get this error message, if you do I'll give you a hug."); } }