/// <summary> /// Present a dialog to add a parameter to RebarShapeDef. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void addParameterButton_Click(object sender, EventArgs e) { using (AddParameter addParam = new AddParameter(m_rebarShapeDef.Parameters)) { if (DialogResult.OK == addParam.ShowDialog()) { Type paramType = addParam.IsFormula ? typeof(RebarShapeParameterFormula) : typeof(RebarShapeParameterDouble); object paramName = addParam.ParamName; object paramValue = addParam.ParamValue; if (!addParam.IsFormula) { paramValue = double.Parse(addParam.ParamValue); } // Add the parameter to RebarShapeDef. RebarShapeParameter param = m_rebarShapeDef.AddParameter(paramType, paramName, paramValue); propertyGrid.SelectedObject = param; m_parametersListBoxBinding.ResetBindings(false); parameterListBox.SelectedItem = param; } } }
/// <summary> /// Add a parameter to RebarShapeDefinition. /// </summary> /// <param name="parameterType">Parameter type: /// (type of RebarShapeParameterDouble or type of RebarShapeParameterFormula)</param> /// <param name="name">Parameter name</param> /// <param name="value">Parameter value (double value or formula string)</param> /// <returns></returns> public RebarShapeParameter AddParameter(Type parameterType, object name, object value) { RebarShapeParameter param = Activator.CreateInstance(parameterType, this, name, value) as RebarShapeParameter; m_parameters.Add(param); return(param); }
/// <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 (destinationType == typeof(String) && value is RebarShapeParameter) { RebarShapeParameter param = value as RebarShapeParameter; if (null != param) { return(param.Name); } } throw new Exception("Can't be converted to other types except string."); }