using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace CoreUnit.Common.Dialog { public partial class SetSingleValueDialog : FormBase { public Type ValueType { get; private set; } = null; public object Value { get; private set; } = null; public SetSingleValueDialog(Type valueType) { InitializeComponent(); ValueType = valueType; } private void buttonSet_Click(object sender, EventArgs e) { try { string str = textBoxInput.Text; if (ValueType == typeof(int)) { Value = Convert.ToInt32(str); } else if (ValueType == typeof(short)) { Value = Convert.ToInt16(str); } else if (ValueType == typeof(long)) { Value = Convert.ToInt64(str); } else if (ValueType == typeof(uint)) { Value = Convert.ToUInt32(str); } else if (ValueType == typeof(ushort)) { Value = Convert.ToUInt16(str); } else if (ValueType == typeof(ulong)) { Value = Convert.ToUInt64(str); } else if (ValueType == typeof(float)) { Value = Convert.ToSingle(str); } else if (ValueType == typeof(double)) { Value = Convert.ToDouble(str); } else if (ValueType == typeof(byte)) { Value = Convert.ToByte(str); } else if (ValueType == typeof(char)) { Value = Convert.ToChar(str); } else if (ValueType == typeof(bool)) { Value = Convert.ToBoolean(str); } else if (ValueType == typeof(string)) { Value = str; } else { MessageBox.Show("Not defined value type"); DialogResult = DialogResult.Cancel; Close(); return; } DialogResult = DialogResult.OK; Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } }