Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions src/Core/src/Converters/EasingTypeConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,30 @@
using System.Globalization;
using static Microsoft.Maui.Easing;

#nullable disable

namespace Microsoft.Maui.Converters
{
/// <inheritdoc/>
public class EasingTypeConverter : TypeConverter
{
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
public override bool CanConvertFrom(ITypeDescriptorContext? context, Type sourceType)
=> sourceType == typeof(string) || sourceType == typeof(Func<double, double>);

public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
public override bool CanConvertTo(ITypeDescriptorContext? context, Type? destinationType)
=> destinationType == typeof(string);

public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
public override object? ConvertFrom(ITypeDescriptorContext? context, CultureInfo? culture, object value)
{
if (value is null)
{
return null;
}

var strValue = value as string ?? value.ToString();

if (string.IsNullOrWhiteSpace(strValue))
{
return null;
}

var parts = strValue.Split('.');
if (parts.Length == 2 && Compare(parts[0], nameof(Easing)))
Expand All @@ -50,10 +52,12 @@ static bool Compare(string left, string right) =>
left.Equals(right, StringComparison.OrdinalIgnoreCase);
}

public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
public override object? ConvertTo(ITypeDescriptorContext? context, CultureInfo? culture, object? value, Type destinationType)
{
if (value is not Easing easing)
{
throw new NotSupportedException();
}

return easing switch
{
Expand All @@ -72,13 +76,13 @@ _ when easing.Equals(SpringOut) => nameof(SpringOut),
};
}

public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
public override bool GetStandardValuesSupported(ITypeDescriptorContext? context)
=> true;

public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
public override bool GetStandardValuesExclusive(ITypeDescriptorContext? context)
=> false;

public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
public override StandardValuesCollection? GetStandardValues(ITypeDescriptorContext? context)
=> new(new[] {
"Linear",
"SinOut",
Expand Down
Loading
Loading