Beispiel #1
0
 public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
 {
     if (destinationType == typeof(System.String) && value is CAge)
     {
         CAge obj = (CAge)value;
         return(string.Format(@"{0}{1}", obj.Age, obj.Unit));
     }
     return(base.ConvertTo(context, culture, value, destinationType));
 }
Beispiel #2
0
        public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
        {
            if (value is string)
            {
                string str = value as string;
                CAge   obj = new CAge();
                obj.Unit = str.Substring(str.Length - 1, 1);
                obj.Age  = int.Parse(str.Substring(0, str.Length - 1));

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