I have form with lot's of TextBoxes and also there is a lot of threads in my program that need to read content's of those TextBoxes (settings). Since I can't access controls from other threads, I decided to make special class that will hold all the settings, and if user changes some, control will invoke OnTextChanged event and change corresponding value in class. But if I use that approach there will be a lot of similar handlers tike this
private void txtCrap1_TextChanged(object sender, EventArgs e)
{
Settings.Crap1 = txtCrap1.Text;
}
What I want is to do something like this
private void SetUpControlBindings()
{
AddBinding(txtCrap1, Settings.Crap1);
AddBinding(txtCrap2, Settings.Crap2);
}
private void AddBinding(object control, object value)
{
//Add entry to some kind of dictionary
}
private void UpdateValue(object sender, EventArgs e)
{
if (sender is TextBox)
{
//Search it in dictionary and change appropriate value
}
}
But I can't find any pointers to variables in C# Any ideas how to do this?
P.S. I can't use reflection since my code will be obfuscated after compilation
upd: Actually my program is a bit more complicated. I have not only textboxes, but CheckBoxes, NumericUpDowns etc. also I want my Settings class to hold some additional objects like Lists.