Пример #1
0
 public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
 {
     if (value is string text)
     {
         return(FontSpacing.Parse(text));
     }
     else if (value is int i)
     {
         return(new FontSpacing(i));
     }
     return(base.ConvertFrom(context, culture, value));
 }
Пример #2
0
        public static bool TryParse(string s, out FontSpacing result)
        {
            if (s == null)
            {
                result = FontSpacing.Empty;
                return(false);
            }
            var items     = s.Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries);
            var valueList = new List <int>(items.Length);

            for (var i = 0; i < items.Length; i++)
            {
                if (int.TryParse(items[i], out var v) == true)
                {
                    valueList.Add(v);
                }
                else
                {
                    result = FontSpacing.Empty;
                    return(false);
                }
            }
            switch (valueList.Count)
            {
            case 1:
            {
                var value0 = valueList[0];
                result = new FontSpacing(value0, value0);
                return(true);
            }

            case 2:
            {
                var value0 = valueList[0];
                var value1 = valueList[1];
                result = new FontSpacing(value0, value1);
                return(true);
            }

            default:
            {
                result = FontSpacing.Empty;
                return(false);
            }
            }
        }