Exemplo n.º 1
0
 public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
 {
     try
     {
         return(TextStyleStack.Parse((string)value));
     }
     catch
     {
         throw new Exception("convertfrom failed");
     }
 }
Exemplo n.º 2
0
        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
        {
            try
            {
                if (destinationType == null)
                {
                    throw new ArgumentNullException(nameof(destinationType));
                }

                if (value == null)
                {
                    throw new ArgumentNullException(nameof(value));
                }

                var strValue = ConvertToInvariantString(context, value);
                if (destinationType == typeof(string))
                {
                    return(value.ToString());
                }
                if (destinationType == typeof(InstanceDescriptor))
                {
                    var info = TargetType.GetField(strValue);
                    if (info != null)
                    {
                        return(new InstanceDescriptor(info, null));
                    }
                }
                if (destinationType == TargetType)
                {
                    return(TextStyleStack.Parse(strValue));
                }
                throw new Exception("convertto failed");
            }
            catch
            {
                throw new Exception("convertto failed unknown");
            }
        }