Exemplo n.º 1
0
        /// <summary>
        /// Converts the given value object to the specified type, using the specified context and culture information.
        /// </summary>
        /// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext" /> that provides a format context.</param>
        /// <param name="culture">A <see cref="T:System.Globalization.CultureInfo" />. If null is passed, the current culture is assumed.</param>
        /// <param name="value">The <see cref="T:System.Object" /> to convert.</param>
        /// <param name="destinationType">The <see cref="T:System.Type" /> to convert the <paramref name="value" /> parameter to.</param>
        /// <returns>
        /// An <see cref="T:System.Object" /> that represents the converted value.
        /// </returns>
        public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
        {
            ConnectionStringBuilderFacade builder = value as ConnectionStringBuilderFacade;

            if (destinationType == typeof(System.String) && value != null)
            {
                return(builder.ToString());
            }

            return(base.ConvertTo(context, culture, value, destinationType));
        }
Exemplo n.º 2
0
        /// <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="T:System.ComponentModel.ITypeDescriptorContext" /> that provides a format context.</param>
        /// <param name="culture">The <see cref="T:System.Globalization.CultureInfo" /> to use as the current culture.</param>
        /// <param name="value">The <see cref="T:System.Object" /> to convert.</param>
        /// <returns>
        /// An <see cref="T:System.Object" /> that represents the converted value.
        /// </returns>
        /// <exception cref="System.ArgumentException">Can not convert ' + (string)value + ' to type SpellingOptions</exception>
        public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
        {
            string connectionString = value as string;

            if (connectionString != null)
            {
                try
                {
                    ConnectionStringSettings      newSettings = new ConnectionStringSettings("SACSEntitiesContainer", connectionString, "System.Data.EntityClient");
                    ConnectionStringBuilderFacade facade      = new ConnectionStringBuilderFacade(newSettings);
                    return(facade);
                }
                catch
                {
                    throw new ArgumentException(
                              "Can not convert '" + (string)value +
                              "' to type SpellingOptions");
                }
            }
            return(base.ConvertFrom(context, culture, value));
        }