Example #1
0
        /// <summary>
        /// Converts a string object to a C45DebugParameter object
        /// </summary>
        /// <param name="context">An ITypeDescriptorContext that provides a format context.</param>
        /// <param name="culture">The CultureInfo to use as the current culture</param>
        /// <param name="value">The Object to convert</param>
        /// <returns></returns>
        public override object ConvertFrom(ITypeDescriptorContext context,
                                           System.Globalization.CultureInfo culture,
                                           object value)
        {
            object returnValue = null;

            if (value.GetType() == Type.GetType("String"))
            {
                try
                {
                    String   s      = (String)ConvertTo(value, Type.GetType("String"));
                    String[] values = s.Split(@"/".ToCharArray());

                    C45DebugParameter debugParameter = (C45DebugParameter)ConvertTo(value, Type.GetType("C45DebugParameter"));
                    debugParameter.DebugMode   = Convert.ToInt32(values[0]);
                    debugParameter.SnifferHost = values[1];
                    debugParameter.SnifferPort = Convert.ToInt32(values[2]);
                    debugParameter.Verbosity   = Convert.ToInt32(values[2]);

                    returnValue = debugParameter;
                }
                catch (Exception ex)
                {
                    throw (new ArgumentException("Can not convert '" + value + "' to type C45DebugParameter", ex));
                }
            }
            else
            {
                returnValue = base.ConvertFrom(context,
                                               culture,
                                               value);
            }
            return(returnValue);
        }
Example #2
0
        /// <summary>
        /// Converts C45DebugParameter object to string
        /// </summary>
        /// <param name="context">An ITypeDescriptorContext that provides a format context.</param>
        /// <param name="culture">A CultureInfo object. If null is passed, the current culture is assumed.</param>
        /// <param name="value">The Object to convert.</param>
        /// <param name="destinationType">The Type to convert the value parameter to.</param>
        /// <returns></returns>
        public override object ConvertTo(ITypeDescriptorContext context,
                                         System.Globalization.CultureInfo culture,
                                         object value,
                                         Type destinationType)
        {
            object returnValue = new object();

            if (destinationType.GetType() == Type.GetType("String") &&
                value.GetType() == Type.GetType("C45DebugParameter"))
            {
                C45DebugParameter debugParameter = (C45DebugParameter)ConvertTo(value, Type.GetType("C45DebugParameter"));
                String            s = debugParameter.DebugMode.ToString()
                                      + @"/"
                                      + debugParameter.SnifferHost
                                      + @"/"
                                      + debugParameter.SnifferPort.ToString()
                                      + @"/"
                                      + debugParameter.Verbosity.ToString();
                returnValue = s;
            }
            else
            {
                base.ConvertTo(context, culture, value, destinationType);
            }

            return(returnValue);
        }