Beispiel #1
0
        protected override ConversionResult <ViewStates> Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            switch (value)
            {
            case bool boolValue:
                return(ConversionResult <ViewStates> .SetValue(boolValue?ViewStates.Invisible : ViewStates.Visible));

            case int intValue:
                return(ConversionResult <ViewStates> .SetValue(intValue > 0?ViewStates.Invisible : ViewStates.Visible));

            case float floatValue:
                return(ConversionResult <ViewStates> .SetValue(floatValue > 0?ViewStates.Invisible : ViewStates.Visible));

            case double doubleValue:
                return(ConversionResult <ViewStates> .SetValue(doubleValue > 0?ViewStates.Invisible : ViewStates.Visible));

            case string stringValue:
                return(ConversionResult <ViewStates> .SetValue(!string.IsNullOrEmpty(stringValue)?ViewStates.Invisible : ViewStates.Visible));

            case IEnumerable <object> enumerableValue:
                return(ConversionResult <ViewStates> .SetValue(enumerableValue?.Any() ?? false?ViewStates.Invisible : ViewStates.Visible));

            default:
                return(ConversionResult <ViewStates> .SetValue(value != null?ViewStates.Invisible : ViewStates.Visible));
            }
        }
        protected override ConversionResult <object> ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (targetType.IsInstanceOfType(value))
            {
                return(ConversionResult <object> .SetValue(value));
            }

            switch (value)
            {
#if __IOS__
            case NSDate dateTimeValue when targetType == typeof(DateTime):
                return(ConversionResult <object> .SetValue((DateTime)dateTimeValue));

            case NSDate dateTimeValue when targetType == typeof(DateTime?):
                return(ConversionResult <object> .SetValue((DateTime?)dateTimeValue));

            case NSDate dateTimeValue when targetType == typeof(DateTimeOffset):
                return(ConversionResult <object> .SetValue((DateTimeOffset)(DateTime)dateTimeValue));

            case NSDate dateTimeValue when targetType == typeof(DateTimeOffset?):
                return(ConversionResult <object> .SetValue((DateTimeOffset?)(DateTime?)dateTimeValue));

            case nint enumValue when targetType.IsEnum:
                return(ConversionResult <object> .SetValue(Enum.ToObject(targetType, enumValue)));
#endif
            case int enumValue when targetType.IsEnum:
                return(ConversionResult <object> .SetValue(Enum.ToObject(targetType, enumValue)));
            }

            return(ConversionResult <object> .SetValue(System.Convert.ChangeType(value, targetType)));
        }
        protected override ConversionResult <bool> Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            switch (value)
            {
            case bool boolValue:
                return(ConversionResult <bool> .SetValue(!boolValue));

            case int intValue:
                return(ConversionResult <bool> .SetValue(!(intValue > 0)));

            case float floatValue:
                return(ConversionResult <bool> .SetValue(!(floatValue > 0)));

            case double doubleValue:
                return(ConversionResult <bool> .SetValue(!(doubleValue > 0)));

            case string stringValue:
                return(ConversionResult <bool> .SetValue(string.IsNullOrEmpty(stringValue)));

            case IEnumerable <object> enumerableValue:
                return(ConversionResult <bool> .SetValue(!(enumerableValue?.Any() ?? false)));

            default:
                return(ConversionResult <bool> .SetValue(value == null));
            }
        }
        protected override ConversionResult <object> Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (targetType.IsInstanceOfType(value))
            {
                return(ConversionResult <object> .SetValue(value));
            }

            switch (value)
            {
#if __IOS__
            // https://docs.microsoft.com/en-us/xamarin/cross-platform/macios/nativetypes
            case int intValue when targetType == typeof(nint):
                return(ConversionResult <object> .SetValue((nint)intValue));

            case long longValue when targetType == typeof(nint):
                return(ConversionResult <object> .SetValue((nint)longValue));

            case uint uintValue when targetType == typeof(nuint):
                return(ConversionResult <object> .SetValue((nuint)uintValue));

            case ulong ulongValue when targetType == typeof(nuint):
                return(ConversionResult <object> .SetValue((nuint)ulongValue));

            case float floatValue when targetType == typeof(nfloat):
                return(ConversionResult <object> .SetValue((nfloat)floatValue));

            case double doubleValue when targetType == typeof(nfloat):
                return(ConversionResult <object> .SetValue((nfloat)doubleValue));

            case DateTime dateTimeValue when targetType == typeof(NSDate):
                return(ConversionResult <object> .SetValue((NSDate)dateTimeValue));

            case DateTimeOffset dateTimeOffsetValue when targetType == typeof(NSDate):
                return(ConversionResult <object> .SetValue((NSDate)dateTimeOffsetValue.UtcDateTime));

            case Enum enumValue when targetType == typeof(nint):
                return(ConversionResult <object> .SetValue((nint)System.Convert.ToInt32(enumValue)));
#endif
            case Enum enumValue when targetType == typeof(int):
                return(ConversionResult <object> .SetValue(System.Convert.ToInt32(enumValue)));

            case NamedValue namedValue when targetType == typeof(string):
                return(ConversionResult <object> .SetValue(namedValue.ToString()));
            }

            return(ConversionResult <object> .SetValue(System.Convert.ChangeType(value, targetType)));
        }
Beispiel #5
0
        protected override ConversionResult <object> ConvertBack(ViewStates value, Type targetType, object parameter, CultureInfo culture)
        {
            switch (targetType)
            {
            case Type boolType when boolType == typeof(bool):
                return(ConversionResult <object> .SetValue(value == ViewStates.Invisible));

            case Type intType when intType == typeof(int):
                return(ConversionResult <object> .SetValue(value == ViewStates.Invisible? 1 : 0));

            case Type floatType when floatType == typeof(float):
                return(ConversionResult <object> .SetValue(value == ViewStates.Invisible? 1 : 0));

            case Type doubleType when doubleType == typeof(double):
                return(ConversionResult <object> .SetValue(value == ViewStates.Invisible? 1 : 0));

            default:
                return(ConversionResult <object> .UnsetValue());
            }
        }
Beispiel #6
0
 protected override ConversionResult <bool> ConvertBack(ViewStates value, Type targetType, object parameter, CultureInfo culture)
 {
     return(ConversionResult <bool> .SetValue(value == ViewStates.Visible));
 }
Beispiel #7
0
 protected override ConversionResult <ViewStates> Convert(bool value, Type targetType, object parameter, CultureInfo culture)
 {
     return(ConversionResult <ViewStates> .SetValue(value?ViewStates.Visible : ViewStates.Invisible));
 }
Beispiel #8
0
 protected override ConversionResult <bool> ConvertBack(bool value, Type targetType, object parameter, CultureInfo culture)
 {
     return(ConversionResult <bool> .SetValue(!value));
 }