Exemplo n.º 1
0
        /// <inheritdoc />
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            var text = value as string;

            if (text != null)
            {
                VolumeUnit result;
                if (VolumeUnit.TryParse(text, out result))
                {
                    return(result);
                }

                var message = $"Could not convert the string '{text}' to an instance of VolumeUnit)";
                throw new NotSupportedException(message);
            }

            return(base.ConvertFrom(context, culture, value));
        }