/// <summary> /// Apply value type settings. /// </summary> /// <param name="context">The current type context.</param> /// <param name="provider">The current service provider.</param> /// <param name="value">The value sent by the client</param> /// <returns>The value returned by the service.</returns> public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { ConnectionTypeModel newValue = null; if (context != null && context.Instance != null && provider != null) { // Get the windows service editor edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService)); if (edSvc != null) { // Create a new desginer type. ConnectionTypeFormDesigner design = new ConnectionTypeFormDesigner(); // If the value sent is not null if (value != null) { // If the value sent is of type connection type model // else throw an exception. if (value is ConnectionTypeModel) { design.ConnectionTypeModel = (ConnectionTypeModel)value; } else { throw new TypeLoadException("Value must be of type 'Nequeo.ComponentModel.ConnectionTypeModel'"); } } // Show the designer and assign the // set values. edSvc.ShowDialog(design); newValue = design.ConnectionTypeModel; } } return(newValue); }
/// <summary> /// Converts the given value object to the specified type, using the specified /// context and culture information. /// </summary> /// <param name="context">An System.ComponentModel.ITypeDescriptorContext that provides a format context.</param> /// <param name="culture">A System.Globalization.CultureInfo. If null is passed, the current culture is assumed.</param> /// <param name="value">The System.Object to convert.</param> /// <param name="destinationType">The System.Type to convert the value parameter to.</param> /// <returns>An System.Object that represents the converted value.</returns> public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { if (value != null) { // Is the value of type ConnectionTypeModel if (!(value is ConnectionTypeModel)) { // Throw exception if type is not support. throw new ArgumentException( "Invalid Connection Type Model", "value"); } } // If the destination type is a string type if (destinationType == typeof(string)) { if (value == null) { // Return empty string. return(String.Empty); } // Cast the value to type to a ConnectionTypeModel type. ConnectionTypeModel model = (ConnectionTypeModel)value; // Format the model type to a string type form. return(String.Format("{0}, {1}, {2}, {3}, {4}", model.DataObjectTypeName, model.DatabaseConnection, model.ConnectionType, model.ConnectionDataType, model.DataAccessProvider)); } return(base.ConvertTo(context, culture, value, destinationType)); }