public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { if (!(value is string str)) { return(new double[0]); } if (string.IsNullOrWhiteSpace(str)) { return(new double[0]); } var vals = str.Split(','); var beatDivisors = new double[vals.Length]; for (int i = 0; i < vals.Length; i++) { var val = vals[i]; var valid = TypeConverters.TryParseDouble(val, out double doubleValue); if (valid) { beatDivisors[i] = doubleValue; } else { return(new ValidationResult(false, "Double format error.")); } } return(beatDivisors); }
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { if (!(value is string str)) { return(null); } try { return(TypeConverters.ParseOsuTimestamp(str).TotalMilliseconds); } catch (Exception e) { Console.WriteLine(e); } if (parameter is string s) { return(TypeConverters.TryParseDouble(str, out double result2) ? result2 : double.Parse(s, CultureInfo.InvariantCulture)); } if (TypeConverters.TryParseDouble(str, out double result3)) { return(result3); } return(new ValidationResult(false, "Time format error.")); }
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { if (value == null) { if (parameter != null) { return(double.Parse(parameter.ToString())); } return(new ValidationResult(false, "Cannot convert back null.")); } if (value.ToString() == "727 WYSI") { return(727); } if (parameter == null) { if (TypeConverters.TryParseDouble(value.ToString(), out double result1)) { return(result1); } return(new ValidationResult(false, "Double format error.")); } TypeConverters.TryParseDouble(value.ToString(), out double result2, double.Parse(parameter.ToString())); return(result2); }
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { if (!(value is string str)) { return(null); } var bracketIndex = str.IndexOf("(", StringComparison.Ordinal); if (TimeSpan.TryParseExact(str.Substring(0, bracketIndex == -1 ? str.Length : bracketIndex - 1).Trim(), @"mm\:ss\:fff", culture, TimeSpanStyles.None, out var result)) { return(result.TotalMilliseconds); } if (parameter is string s) { return(TypeConverters.TryParseDouble(str, out double result2) ? result2 : double.Parse(s, CultureInfo.InvariantCulture)); } if (TypeConverters.TryParseDouble(str, out double result3)) { return(result3); } return(new ValidationResult(false, "Time format error.")); }
public override ValidationResult Validate(object value, CultureInfo cultureInfo) { double limit = ValueWrapper.Value; string str = (value ?? "").ToString(); if (!TypeConverters.TryParseDouble(str, out double result)) { return(new ValidationResult(false, "Double format error.")); } return(result <= limit ? ValidationResult.ValidResult : new ValidationResult(false, $"Value can not be greater than {limit}.")); }
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { if (!(value is string str)) { return(new IBeatDivisor[0]); } var vals = str.Split(','); var beatDivisors = new IBeatDivisor[vals.Length]; for (int i = 0; i < vals.Length; i++) { var val = vals[i]; // Check if it is a positive rational and non-zero and not dividing by zero if (Regex.IsMatch(val, "^[\\s]*[1-9][0-9]*[\\s]*/[\\s]*[1-9][0-9]*[\\s]*$")) { var ndSplit = val.Split('/'); beatDivisors[i] = new RationalBeatDivisor(int.Parse(ndSplit[0], CultureInfo.InvariantCulture), int.Parse(ndSplit[1], CultureInfo.InvariantCulture)); } else { var valid = TypeConverters.TryParseDouble(val, out double doubleValue); if (valid) { if (doubleValue <= 0) { return(new ValidationResult(false, "Beat divisor must be greater than zero.")); } beatDivisors[i] = new IrrationalBeatDivisor(doubleValue); } else { return(new ValidationResult(false, "Double format error.")); } } } return(beatDivisors); }
private async void ScaleCompleteButton_OnClick(object sender, RoutedEventArgs e) { var dialog = new TypeValueDialog(1); var result = await DialogHost.Show(dialog, "RootDialog"); if (!(bool)result) { return; } if (!TypeConverters.TryParseDouble(dialog.ValueBox.Text, out var value)) { return; } var maxValue = GetMaxCompletion(); if (Math.Abs(maxValue) < Precision.DOUBLE_EPSILON) { return; } Graph.ScaleAnchors(new Size(1, value / maxValue)); }
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { TypeConverters.TryParseDouble(value.ToString(), out double result, double.Parse(parameter.ToString())); return(result / 100); }