Пример #1
0
        protected override ConversionResult <string> Convert(VacationStatus value, Type targetType, object parameter, CultureInfo culture)
        {
            string text = String.Empty;

            switch (value)
            {
            case VacationStatus.Approved:
                text = Strings.Approved;
                break;

            case VacationStatus.Closed:
                text = Strings.Closed;
                break;

            case VacationStatus.Draft:
                text = Strings.Draft;
                break;


            case VacationStatus.InProgress:
                text = Strings.InProgress;
                break;


            case VacationStatus.Submitted:
                text = Strings.Submitted;
                break;
            }

            return(ConversionResult <string> .SetValue(text));
        }
        protected override ConversionResult <UIImage> Convert(VacationType value, Type targetType, object parameter, CultureInfo culture)
        {
            UIImage image;

            switch (value)
            {
            case VacationType.Regular:
                image = UIImage.FromBundle("IconRequestGreen");
                break;

            case VacationType.Sick:
                image = UIImage.FromBundle("IconRequestPlum");
                break;

            case VacationType.Exceptional:
                image = UIImage.FromBundle("IconRequestGray");
                break;

            case VacationType.Overtime:
                image = UIImage.FromBundle("IconRequestBlue");
                break;

            case VacationType.LeaveWithoutPay:
                image = UIImage.FromBundle("IconRequestDark");
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(value), value, null);
            }

            return(ConversionResult <UIImage> .SetValue(image));
        }
Пример #3
0
        protected override ConversionResult <int> Convert(VacationType value, Type targetType, object parameter, CultureInfo culture)
        {
            int imageId;

            switch (value)
            {
            case VacationType.Regular:
                imageId = Resource.Drawable.Icon_Request_Green;
                break;

            case VacationType.Sick:
                imageId = Resource.Drawable.Icon_Request_Plum;
                break;

            case VacationType.Exceptional:
                imageId = Resource.Drawable.Icon_Request_Gray;
                break;

            case VacationType.Overtime:
                imageId = Resource.Drawable.Icon_Request_Blue;
                break;

            case VacationType.LeaveWithoutPay:
                imageId = Resource.Drawable.Icon_Request_Dark;
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(value), value, null);
            }

            return(ConversionResult <int> .SetValue(imageId));
        }
Пример #4
0
        protected override ConversionResult <DateTime> ConvertBack(NSDate value, Type targetType, object parameter, CultureInfo culture)
        {
            var date = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(2001, 1, 1, 0, 0, 0))
                       .AddSeconds(value.NotNull().SecondsSinceReferenceDate);

            return(ConversionResult <DateTime> .SetValue(date));
        }
Пример #5
0
        protected override ConversionResult <int> Convert(VacationType value, Type targetType, object parameter, CultureInfo culture)
        {
            int resourseId;

            switch (value)
            {
            case VacationType.Regular:
                resourseId = Resource.Drawable.Icon_Request_Green;
                break;

            case VacationType.Exceptional:
                resourseId = Resource.Drawable.Icon_Request_Dark;
                break;

            case VacationType.Overtime:
                resourseId = Resource.Drawable.Icon_Request_Blue;
                break;

            case VacationType.Sick:
                resourseId = Resource.Drawable.Icon_Request_Plum;
                break;

            case VacationType.LeaveWithoutPay:
                resourseId = Resource.Drawable.Icon_Request_Orange;
                break;

            default:
                resourseId = Resource.Drawable.Icon_Request_Gray;
                break;
            }

            return(ConversionResult <int> .SetValue(resourseId));
        }
        protected override ConversionResult <UIImage> Convert(VacationType value, Type targetType, object parameter, CultureInfo culture)
        {
            UIImage image = null;

            switch (value)
            {
            case VacationType.Regular:
                image = AppImages.IconRequestGreen;
                break;

            case VacationType.Exceptional:
                image = AppImages.IconRequestDark;
                break;

            case VacationType.Overtime:
                image = AppImages.IconRequestBlue;
                break;

            case VacationType.Sick:
                image = AppImages.IconRequestRed;
                break;

            case VacationType.LeaveWithoutPay:
                image = AppImages.IconRequestOrange;
                break;

            case VacationType.Undefined:
                image = AppImages.IconRequestGrey;
                break;
            }

            return(ConversionResult <UIImage> .SetValue(image));
        }
Пример #7
0
        protected override ConversionResult <NSDate> Convert(DateTime value, Type targetType, object parameter, CultureInfo culture)
        {
            var startTime = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(2001, 1, 1, 0, 0, 0));
            var nsDate    = NSDate.FromTimeIntervalSinceReferenceDate((value - startTime).TotalSeconds);

            return(ConversionResult <NSDate> .SetValue(nsDate));
        }
        protected override ConversionResult <Drawable> Convert(int value, Type targetType, object parameter, CultureInfo culture)
        {
            int image = 0;

            switch (value)
            {
            case 1:
                image = Resource.Drawable.Icon_Request_Green;
                break;

            case 2:
                image = Resource.Drawable.Icon_Request_Plum;
                break;

            case 3:
                image = Resource.Drawable.Icon_Request_Gray;
                break;

            case 4:
                image = Resource.Drawable.Icon_Request_Dark;
                break;

            case 5:
                image = Resource.Drawable.Icon_Request_Blue;
                break;
            }

            var drawable = CrossCurrentActivity.Current.AppContext.Resources.GetDrawable(image);

            return(ConversionResult <Drawable> .SetValue(drawable));
        }
Пример #9
0
        protected override ConversionResult <string> Convert(VacationType value, Type targetType, object parameter, CultureInfo culture)
        {
            string text = String.Empty;

            switch (value)
            {
            case VacationType.Regular:
                text = Strings.Regular;
                break;

            case VacationType.Exceptional:
                text = Strings.ExceptionalLeave;
                break;

            case VacationType.Overtime:
                text = Strings.Overtime;
                break;

            case VacationType.Sick:
                text = Strings.SickDays;
                break;

            case VacationType.LeaveWithoutPay:
                text = Strings.LeaveWithoutPay;
                break;

            case VacationType.Undefined:
                text = Strings.Undefined;
                break;
            }

            return(ConversionResult <string> .SetValue(text));
        }
        protected override ConversionResult <DateTime> Convert(string value, Type targetType, object parameter, CultureInfo culture)
        {
            if (DateTime.TryParse(value, out var dt))
            {
                return(ConversionResult <DateTime> .SetValue(new DateTime(dt.Year, dt.Month, dt.Day, 0, 0, 0, DateTimeKind.Utc)));
            }

            return(ConversionResult <DateTime> .SetValue(DateTime.UtcNow));
        }
        protected override ConversionResult <int> ConvertBack(string value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            return(ConversionResult <int> .SetValue(int.Parse(value)));
        }
        protected override ConversionResult <TValue> Convert(TSource value, Type targetType, object parameter, CultureInfo culture)
        {
            var dictionary = GetMapping(parameter);

            if (dictionary.ContainsKey(value))
            {
                return(ConversionResult <TValue> .SetValue(dictionary[value]));
            }
            else
            {
                return(ConversionResult <TValue> .UnsetValue());
            }
        }
        protected override ConversionResult <TSource> ConvertBack(TValue value, Type targetType, object parameter, CultureInfo culture)
        {
            var dictionary = GetMapping(parameter);

            if (dictionary.ContainsValue(value))
            {
                return(ConversionResult <TSource> .SetValue(dictionary.FirstOrDefault(x => x.Value.Equals(value)).Key));
            }
            else
            {
                return(ConversionResult <TSource> .UnsetValue());
            }
        }
        protected override ConversionResult <nint> Convert(VacationStatus value, Type targetType, object parameter, CultureInfo culture)
        {
            nint index = 0;

            switch (value)
            {
            case VacationStatus.Approved:
                index = 0;
                break;

            case VacationStatus.Closed:
                index = 1;
                break;
            }

            return(ConversionResult <nint> .SetValue(index));
        }
        protected override ConversionResult <int> Convert(VacationStatus value, Type targetType, object parameter, CultureInfo culture)
        {
            int resourseId = -1;

            switch (value)
            {
            case VacationStatus.Approved:
                resourseId = Resource.Id.approved_radio;
                break;

            case VacationStatus.Closed:
                resourseId = Resource.Id.closed_radio;
                break;
            }

            return(ConversionResult <int> .SetValue(resourseId));
        }
        protected override ConversionResult <VacationStatus> ConvertBack(int value, Type targetType, object parameter, CultureInfo culture)
        {
            var vacationStatus = VacationStatus.Approved;

            switch (value)
            {
            case Resource.Id.approved_radio:
                vacationStatus = VacationStatus.Approved;
                break;

            case Resource.Id.closed_radio:
                vacationStatus = VacationStatus.Closed;
                break;
            }

            return(ConversionResult <VacationStatus> .SetValue(vacationStatus));
        }
        protected override ConversionResult <VacationStatus> ConvertBack(nint value, Type targetType, object parameter, CultureInfo culture)
        {
            VacationStatus status = VacationStatus.Approved;

            switch (value)
            {
            case 0:
                status = VacationStatus.Approved;
                break;

            case 1:
                status = VacationStatus.Closed;
                break;
            }

            return(ConversionResult <VacationStatus> .SetValue(status));
        }
        protected override ConversionResult <int> Convert(BottomTabBarItem value, Type targetType, object parameter, CultureInfo culture)
        {
            switch (value)
            {
            case BottomTabBarItem.Template1:
                return(ConversionResult <int> .SetValue(Resource.Id.template1_item));

            case BottomTabBarItem.Template2:
                return(ConversionResult <int> .SetValue(Resource.Id.template2_item));

            case BottomTabBarItem.Template3:
                return(ConversionResult <int> .SetValue(Resource.Id.template3_item));

            default:
                return(ConversionResult <int> .UnsetValue());
            }
        }
        protected override ConversionResult <BottomTabBarItem> ConvertBack(int value, Type targetType, object parameter, CultureInfo culture)
        {
            switch (value)
            {
            case Resource.Id.template1_item:
                return(ConversionResult <BottomTabBarItem> .SetValue(BottomTabBarItem.Template1));

            case Resource.Id.template2_item:
                return(ConversionResult <BottomTabBarItem> .SetValue(BottomTabBarItem.Template2));

            case Resource.Id.template3_item:
                return(ConversionResult <BottomTabBarItem> .SetValue(BottomTabBarItem.Template3));

            default:
                return(ConversionResult <BottomTabBarItem> .UnsetValue());
            }
        }
Пример #20
0
        protected override ConversionResult <DayOfWeeksFlags> Convert(IEnumerable <DayOfWeek> value, Type targetType, object parameter, CultureInfo culture)
        {
            DayOfWeeksFlags dayOfWeekFlags = DayOfWeeksFlags.None;

            if (value == null)
            {
                return(ConversionResult <DayOfWeeksFlags> .SetValue(dayOfWeekFlags));
            }

            foreach (var dayOfWeek in value)
            {
                switch (dayOfWeek)
                {
                case DayOfWeek.Monday:
                    dayOfWeekFlags = dayOfWeekFlags | DayOfWeeksFlags.Monday;
                    break;

                case DayOfWeek.Thursday:
                    dayOfWeekFlags = dayOfWeekFlags | DayOfWeeksFlags.Thursday;
                    break;

                case DayOfWeek.Tuesday:
                    dayOfWeekFlags = dayOfWeekFlags | DayOfWeeksFlags.Tuesday;
                    break;

                case DayOfWeek.Wednesday:
                    dayOfWeekFlags = dayOfWeekFlags | DayOfWeeksFlags.Wednesday;
                    break;

                case DayOfWeek.Friday:
                    dayOfWeekFlags = dayOfWeekFlags | DayOfWeeksFlags.Friday;
                    break;

                case DayOfWeek.Sunday:
                    dayOfWeekFlags = dayOfWeekFlags | DayOfWeeksFlags.Sunday;
                    break;

                case DayOfWeek.Saturday:
                    dayOfWeekFlags = dayOfWeekFlags | DayOfWeeksFlags.Saturday;
                    break;
                }
            }

            return(ConversionResult <DayOfWeeksFlags> .SetValue(dayOfWeekFlags));
        }
        protected override ConversionResult <int> Convert(VacationStatus value, Type targetType, object parameter, CultureInfo culture)
        {
            int radioButtonId;

            switch (value)
            {
            case VacationStatus.Approved:
                radioButtonId = Resource.Id.approved_radio;
                break;

            case VacationStatus.Closed:
                radioButtonId = Resource.Id.closed_radio;
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(value), value, null);
            }

            return(ConversionResult <int> .SetValue(radioButtonId));
        }
Пример #22
0
        protected override ConversionResult <nint> Convert(VacationStatus value, Type targetType, object parameter, CultureInfo culture)
        {
            nint index;

            switch (value)
            {
            case VacationStatus.Approved:
                index = 0;
                break;

            case VacationStatus.Closed:
                index = 1;
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(value), value, null);
            }

            return(ConversionResult <nint> .SetValue(index));
        }
Пример #23
0
        protected override ConversionResult <VacationStatus> ConvertBack(nint value, Type targetType, object parameter, CultureInfo culture)
        {
            VacationStatus status;

            switch (value)
            {
            case 0:
                status = VacationStatus.Approved;
                break;

            case 1:
                status = VacationStatus.Closed;
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(value), value, null);
            }

            return(ConversionResult <VacationStatus> .SetValue(status));
        }
Пример #24
0
        protected override ConversionResult <IEnumerable <DayOfWeek> > ConvertBack(DayOfWeeksFlags value, Type targetType, object parameter, CultureInfo culture)
        {
            var list = new List <DayOfWeek>();

            if (value.HasFlag(DayOfWeeksFlags.Monday))
            {
                list.Add(DayOfWeek.Monday);
            }

            if (value.HasFlag(DayOfWeeksFlags.Tuesday))
            {
                list.Add(DayOfWeek.Tuesday);
            }

            if (value.HasFlag(DayOfWeeksFlags.Wednesday))
            {
                list.Add(DayOfWeek.Wednesday);
            }

            if (value.HasFlag(DayOfWeeksFlags.Thursday))
            {
                list.Add(DayOfWeek.Thursday);
            }

            if (value.HasFlag(DayOfWeeksFlags.Friday))
            {
                list.Add(DayOfWeek.Friday);
            }

            if (value.HasFlag(DayOfWeeksFlags.Saturday))
            {
                list.Add(DayOfWeek.Saturday);
            }

            if (value.HasFlag(DayOfWeeksFlags.Sunday))
            {
                list.Add(DayOfWeek.Sunday);
            }

            return(ConversionResult <IEnumerable <DayOfWeek> > .SetValue(list));
        }
Пример #25
0
        protected override ConversionResult <object> Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (targetType.IsInstanceOfType(value))
            {
                return(ConversionResult <object> .SetValue(value));
            }
#if __IOS__
            switch (value)
            {
            // 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(Foundation.NSDate):
                return(ConversionResult <object> .SetValue((Foundation.NSDate) dateTimeValue));

            case DateTimeOffset dateTimeOffsetValue when targetType == typeof(Foundation.NSDate):
                return(ConversionResult <object> .SetValue((Foundation.NSDate) dateTimeOffsetValue.UtcDateTime));
            }
#endif
            return(ConversionResult <object> .SetValue(System.Convert.ChangeType(value, targetType)));
        }
Пример #26
0
        protected override ConversionResult <NavigationMenuItem> ConvertBack(int resId, Type targetType, object parameter, CultureInfo culture)
        {
            NavigationMenuItem item;

            switch (resId)
            {
            case Resource.Id.navigation_all:
                item = NavigationMenuItem.All;
                break;

            case Resource.Id.navigation_open:
                item = NavigationMenuItem.Open;
                break;

            case Resource.Id.navigation_closed:
                item = NavigationMenuItem.Closed;
                break;

            default:
                throw new ArgumentException("Invalid resource id", nameof(resId));
            }

            return(ConversionResult <NavigationMenuItem> .SetValue(item));
        }
Пример #27
0
        protected override ConversionResult <object> ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (targetType.IsInstanceOfType(value))
            {
                return(ConversionResult <object> .SetValue(value));
            }
#if __IOS__
            switch (value)
            {
            case Foundation.NSDate dateTimeValue when targetType == typeof(DateTime):
                return(ConversionResult <object> .SetValue((DateTime)dateTimeValue));

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

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

            case Foundation.NSDate dateTimeValue when targetType == typeof(DateTimeOffset?):
                return(ConversionResult <object> .SetValue((DateTimeOffset?)(DateTime?)dateTimeValue));
            }
#endif
            return(ConversionResult <object> .SetValue(System.Convert.ChangeType(value, targetType)));
        }
Пример #28
0
 protected override ConversionResult <bool> ConvertBack(bool value, Type targetType, object parameter, CultureInfo culture)
 {
     return(ConversionResult <bool> .SetValue(!value));
 }
Пример #29
0
        protected override ConversionResult <ViewStates> Convert(int value, Type targetType, object parameter, CultureInfo culture)
        {
            var viewState = value > 0 ? ViewStates.Visible : ViewStates.Gone;

            return(ConversionResult <ViewStates> .SetValue(viewState));
        }
Пример #30
0
 protected override ConversionResult <string> Convert(VacationType value, Type targetType, object parameter, CultureInfo culture)
 {
     return(ConversionResult <string> .SetValue(value.ToFriendlyString()));
 }