Example #1
0
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            if (!(value is string))
            {
                return(base.ConvertFrom(context, culture, value));
            }

            UserOptionsDto userOptionsDto;

            return(UserOptionsDto.TryParse((string)value, out userOptionsDto) ? userOptionsDto : base.ConvertFrom(context, culture, value));
        }
Example #2
0
        public static bool TryParse(string strValue, out UserOptionsDto userOptionsDto)
        {
            userOptionsDto = null;

            var parts = strValue.Split(',');

            if (parts.Length != 2)
            {
                return(false);
            }

            bool part1Value, part2Value, showActiveOnly = false, showPermissions = false;
            int  value1, value2;

            if (int.TryParse(parts[0], out value1))
            {
                showActiveOnly = value1 > 0;
            }
            else if (bool.TryParse(parts[0], out part1Value))
            {
                showActiveOnly = part1Value;
            }

            if (int.TryParse(parts[1], out value2))
            {
                showPermissions = value2 > 0;
            }
            else if (bool.TryParse(parts[1], out part2Value))
            {
                showPermissions = part2Value;
            }

            userOptionsDto = new UserOptionsDto {
                ShowPermissions = showPermissions, ShowActiveOnly = showActiveOnly
            };

            return(true);
        }