/// <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"); } RasEapOptions options = value as RasEapOptions; if (options != null) { if (culture == null) { culture = CultureInfo.CurrentCulture; } if (destinationType == typeof(InstanceDescriptor)) { ConstructorInfo constructor = typeof(RasEapOptions).GetConstructor(new Type[] { typeof(bool), typeof(bool), typeof(bool) }); if (constructor != null) { return(new InstanceDescriptor(constructor, new object[] { options.NonInteractive, options.LogOn, options.Preview })); } } } 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) { var data = (string)value; if (data == null) { return(base.ConvertFrom(context, culture, value)); } data = data.Trim(); if (data.Length == 0) { return(null); } var items = data.Split(culture.TextInfo.ListSeparator.ToCharArray()); var converter = TypeDescriptor.GetConverter(typeof(bool)); var retval = new RasEapOptions { NonInteractive = (bool)converter.ConvertFromString(context, culture, items[0]), LogOn = (bool)converter.ConvertFromString(context, culture, items[1]), Preview = (bool)converter.ConvertFromString(context, culture, items[2]) }; return(retval); }
/// <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)); RasEapOptions retval = new RasEapOptions(); retval.NonInteractive = (bool)converter.ConvertFromString(context, culture, items[0]); retval.LogOn = (bool)converter.ConvertFromString(context, culture, items[1]); retval.Preview = (bool)converter.ConvertFromString(context, culture, items[2]); return retval; }
public void EapOptionsTest() { RasEapOptions expected = new RasEapOptions(true, false, true); RasDialer target = new RasDialer(); target.EapOptions = expected; RasEapOptions actual = target.EapOptions; Assert.AreSame(expected, actual); }