/// <summary> /// Converts the given object to the type of this converter, using the specified context and culture information. /// </summary> /// <param name="context">An <see cref="ITypeDescriptorContext"/> that provides a format context.</param> /// <param name="culture">The <see cref="CultureInfo"/> to use as the current culture.</param> /// <param name="value">The <see cref="System.Object"/> to convert.</param> /// <returns>An <see cref="System.Object"/> that represents the converted value.</returns> public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { string data = (string)value; if (data == null) { return(base.ConvertFrom(context, culture, value)); } data = data.Trim(); if (data.Length == 0) { return(null); } if (culture == null) { culture = CultureInfo.CurrentCulture; } string[] items = data.Split(culture.TextInfo.ListSeparator.ToCharArray()); TypeConverter converter = TypeDescriptor.GetConverter(typeof(bool)); RasDialOptions retval = new RasDialOptions(); retval.UsePrefixSuffix = (bool)converter.ConvertFromString(context, culture, items[0]); retval.PausedStates = (bool)converter.ConvertFromString(context, culture, items[1]); retval.SetModemSpeaker = (bool)converter.ConvertFromString(context, culture, items[2]); retval.SetSoftwareCompression = (bool)converter.ConvertFromString(context, culture, items[3]); retval.DisableConnectedUI = (bool)converter.ConvertFromString(context, culture, items[4]); retval.DisableReconnectUI = (bool)converter.ConvertFromString(context, culture, items[5]); retval.DisableReconnect = (bool)converter.ConvertFromString(context, culture, items[6]); retval.NoUser = (bool)converter.ConvertFromString(context, culture, items[7]); retval.Router = (bool)converter.ConvertFromString(context, culture, items[8]); retval.CustomDial = (bool)converter.ConvertFromString(context, culture, items[9]); #if (WINXP || WIN2K8 || WIN7 || WIN8) retval.UseCustomScripting = (bool)converter.ConvertFromString(context, culture, items[10]); #endif return(retval); }
/// <summary> /// Converts the given value object to the specified type, using the specified context and culture information. /// </summary> /// <param name="context">An <see cref="ITypeDescriptorContext"/> that provides a format context.</param> /// <param name="culture">The <see cref="CultureInfo"/> to use as the current culture.</param> /// <param name="value">The <see cref="System.Object"/> to convert.</param> /// <param name="destinationType">The <see cref="System.Type"/> to convert the <paramref name="value"/> parameter to.</param> /// <returns>An <see cref="System.Object"/> that represents the converted value.</returns> public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { if (destinationType == null) { ThrowHelper.ThrowArgumentNullException("destinationType"); } RasDialOptions options = value as RasDialOptions; if (options != null) { if (culture == null) { culture = CultureInfo.CurrentCulture; } if (destinationType == typeof(InstanceDescriptor)) { List <Type> types = new List <Type>(new Type[] { typeof(bool), typeof(bool), typeof(bool), typeof(bool), typeof(bool), typeof(bool), typeof(bool), typeof(bool), typeof(bool), typeof(bool) }); List <object> values = new List <object>(new object[] { options.UsePrefixSuffix, options.PausedStates, options.SetModemSpeaker, options.SetSoftwareCompression, options.DisableConnectedUI, options.DisableReconnectUI, options.DisableReconnect, options.NoUser, options.Router, options.CustomDial }); #if (WINXP || WIN2K8 || WIN7 || WIN8) types.Add(typeof(bool)); values.Add(options.UseCustomScripting); #endif ConstructorInfo constructor = typeof(RasDialOptions).GetConstructor(types.ToArray()); if (constructor != null) { return(new InstanceDescriptor(constructor, values)); } } } return(base.ConvertTo(context, culture, value, destinationType)); }
/// <summary> /// Converts the given object to the type of this converter, using the specified context and culture information. /// </summary> /// <param name="context">An <see cref="ITypeDescriptorContext"/> that provides a format context.</param> /// <param name="culture">The <see cref="CultureInfo"/> to use as the current culture.</param> /// <param name="value">The <see cref="System.Object"/> to convert.</param> /// <returns>An <see cref="System.Object"/> that represents the converted value.</returns> public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { string data = (string)value; if (data == null) { return base.ConvertFrom(context, culture, value); } data = data.Trim(); if (data.Length == 0) { return null; } if (culture == null) { culture = CultureInfo.CurrentCulture; } string[] items = data.Split(culture.TextInfo.ListSeparator.ToCharArray()); TypeConverter converter = TypeDescriptor.GetConverter(typeof(bool)); RasDialOptions retval = new RasDialOptions(); retval.UsePrefixSuffix = (bool)converter.ConvertFromString(context, culture, items[0]); retval.PausedStates = (bool)converter.ConvertFromString(context, culture, items[1]); retval.SetModemSpeaker = (bool)converter.ConvertFromString(context, culture, items[2]); retval.SetSoftwareCompression = (bool)converter.ConvertFromString(context, culture, items[3]); retval.DisableConnectedUI = (bool)converter.ConvertFromString(context, culture, items[4]); retval.DisableReconnectUI = (bool)converter.ConvertFromString(context, culture, items[5]); retval.DisableReconnect = (bool)converter.ConvertFromString(context, culture, items[6]); retval.NoUser = (bool)converter.ConvertFromString(context, culture, items[7]); retval.Router = (bool)converter.ConvertFromString(context, culture, items[8]); retval.CustomDial = (bool)converter.ConvertFromString(context, culture, items[9]); #if (WINXP || WIN2K8 || WIN7 || WIN8) retval.UseCustomScripting = (bool)converter.ConvertFromString(context, culture, items[10]); #endif return retval; }
public void OptionsTest() { RasDialOptions expected = new RasDialOptions(); RasDialer target = new RasDialer(); target.Options = expected; RasDialOptions actual = target.Options; Assert.AreSame(expected, actual); }