Esempio n. 1
0
 public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
 {
     if (value is string text)
     {
         return(CharacterCollection.Parse(text));
     }
     return(base.ConvertFrom(context, culture, value));
 }
Esempio n. 2
0
        /// <summary>
        /// 0-255,256
        /// </summary>
        public static CharacterCollection Parse(string text)
        {
            if (text == null)
            {
                throw new ArgumentNullException(nameof(text));
            }
            var items      = text.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            var capacity   = GetCapacity(items);
            var characters = new CharacterCollection(capacity);

            Enumerate(items, (item) =>
            {
                var min = item.min;
                var max = item.max;
                for (var i = min; i <= max; i++)
                {
                    characters.Add(i);
                }
            });
            return(characters);
        }