public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
        {
            DataBatch db = value as DataBatch;

            if (db != null)
            {
                if (typeof(string).Equals(destinationType))
                {
                    return(string.Format(CultureInfo.InvariantCulture, "{0},{1},{2},{3}", db.BatchSize, db.Enabled, db.KeyFieldType, db.BatchDelay));
                }
            }
            return(base.ConvertTo(context, culture, value, destinationType));
        }
 public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
 {
     if (value is string)
     {
         DataBatch db = new DataBatch();
         string    s  = value as string;
         if (!string.IsNullOrEmpty(s))
         {
             int pos = s.IndexOf(',');
             if (pos >= 0)
             {
                 string s0 = s.Substring(0, pos);
                 s = s.Substring(pos + 1);
                 if (!string.IsNullOrEmpty(s0))
                 {
                     int n;
                     if (int.TryParse(s0, out n))
                     {
                         db.BatchSize = n;
                     }
                 }
                 pos = s.IndexOf(',');
                 if (pos >= 0)
                 {
                     s0 = s.Substring(0, pos);
                     s  = s.Substring(pos + 1);
                     if (!string.IsNullOrEmpty(s0))
                     {
                         bool b;
                         if (bool.TryParse(s0, out b))
                         {
                             db.Enabled = b;
                         }
                     }
                     if (!string.IsNullOrEmpty(s))
                     {
                         pos = s.IndexOf(',');
                         if (pos >= 0)
                         {
                             s0 = s.Substring(0, pos);
                             s  = s.Substring(pos + 1);
                             db.KeyFieldType = (DbType)Enum.Parse(typeof(DbType), s0);
                             if (!string.IsNullOrEmpty(s))
                             {
                                 int n0;
                                 if (int.TryParse(s, out n0))
                                 {
                                     db.BatchDelay = n0;
                                 }
                             }
                         }
                         else
                         {
                             db.KeyFieldType = (DbType)Enum.Parse(typeof(DbType), s);
                         }
                     }
                 }
             }
         }
         return(db);
     }
     return(base.ConvertFrom(context, culture, value));
 }