Browse Source

Use consistent wording for binding warnings.

"Could not convert" instead of "Cannot convert".
refactor/bindingexpressions-in-valuestore
Steven Kirk 3 years ago
parent
commit
3e2d0a5ec0
  1. 8
      src/Avalonia.Base/Data/Core/BindingExpression.cs
  2. 6
      tests/Avalonia.Base.UnitTests/Data/Core/BindingExpressionTests.cs
  3. 2
      tests/Avalonia.Base.UnitTests/Data/Core/BindingExpressionTests_DataValidation.cs
  4. 2
      tests/Avalonia.Markup.UnitTests/Data/BindingTests_Logging.cs

8
src/Avalonia.Base/Data/Core/BindingExpression.cs

@ -186,7 +186,7 @@ internal class BindingExpression : IObservable<object?>,
var valueString = value?.ToString() ?? "(null)";
var valueTypeName = value?.GetType().FullName ?? "null";
var ex = new InvalidCastException(
$"Cannot convert '{valueString}' ({valueTypeName}) to {type}.");
$"Could not convert '{valueString}' ({valueTypeName}) to {type}.");
_observer?.OnNext(new BindingNotification(ex, BindingErrorType.DataValidationError));
return false;
}
@ -555,7 +555,7 @@ internal class BindingExpression : IObservable<object?>,
var valueString = value?.ToString() ?? "(null)";
var valueTypeName = value?.GetType().FullName ?? "null";
var ex = new InvalidCastException(
$"Cannot convert '{valueString}' ({valueTypeName}) to {targetType} using '{converter}'.", e);
$"Could not convert '{valueString}' ({valueTypeName}) to {targetType} using '{converter}'.", e);
return new BindingNotification(ex, BindingErrorType.Error);
}
}
@ -572,7 +572,7 @@ internal class BindingExpression : IObservable<object?>,
Log(target, $"Could not convert {fallbackName} '{fallback}' to '{TargetType}'.", LogEventLevel.Error);
return AvaloniaProperty.UnsetValue;
}
}
private object? ConvertFrom(TargetTypeConverter? converter, object value)
{
@ -586,7 +586,7 @@ internal class BindingExpression : IObservable<object?>,
var valueString = value?.ToString() ?? "(null)";
var valueTypeName = value?.GetType().FullName ?? "null";
var message = $"Cannot convert '{valueString}' ({valueTypeName}) to '{targetType}'.";
var message = $"Could not convert '{valueString}' ({valueTypeName}) to '{targetType}'.";
if (ShouldLogError(out var target))
Log(target, message, LogEventLevel.Warning);

6
tests/Avalonia.Base.UnitTests/Data/Core/BindingExpressionTests.cs

@ -112,7 +112,7 @@ namespace Avalonia.Base.UnitTests.Data.Core
Assert.Equal(
new BindingNotification(
new InvalidCastException("Cannot convert 'foo' (System.String) to 'System.Int32'."),
new InvalidCastException("Could not convert 'foo' (System.String) to 'System.Int32'."),
BindingErrorType.Error,
42),
result);
@ -134,7 +134,7 @@ namespace Avalonia.Base.UnitTests.Data.Core
Assert.Equal(
new BindingNotification(
new InvalidCastException("Cannot convert 'foo' (System.String) to 'System.Int32'."),
new InvalidCastException("Could not convert 'foo' (System.String) to 'System.Int32'."),
BindingErrorType.Error,
42),
result);
@ -251,7 +251,7 @@ namespace Avalonia.Base.UnitTests.Data.Core
new BindingNotification($"{1.2}"),
new BindingNotification($"{3.4}"),
new BindingNotification(
new InvalidCastException("Cannot convert 'bar' (System.String) to System.Double."),
new InvalidCastException("Could not convert 'bar' (System.String) to System.Double."),
BindingErrorType.DataValidationError)
},
result);

2
tests/Avalonia.Base.UnitTests/Data/Core/BindingExpressionTests_DataValidation.cs

@ -102,7 +102,7 @@ namespace Avalonia.Base.UnitTests.Data.Core
// Exception is thrown by trying to set value to "foo".
new BindingNotification(
new InvalidCastException("Cannot convert 'foo' (System.String) to System.Int32."),
new InvalidCastException("Could not convert 'foo' (System.String) to System.Int32."),
BindingErrorType.DataValidationError),
// Value is set then validation is updated.

2
tests/Avalonia.Markup.UnitTests/Data/BindingTests_Logging.cs

@ -242,7 +242,7 @@ namespace Avalonia.Markup.UnitTests.Data
using (AssertLog(
target,
binding.Path,
"Cannot convert '0.0' (System.Version) to 'Avalonia.Thickness'.",
"Could not convert '0.0' (System.Version) to 'Avalonia.Thickness'.",
property: Control.MarginProperty))
{
target.Bind(Control.MarginProperty, binding);

Loading…
Cancel
Save