Usually, if the object was a class instance, I'd use reflection to set values to its members. Consider the following:
class Foo
{
public Control _tCtrl { get; set; }
public Object _tObj { get; set; }
public void Set()
{
// How do I give tObj the converted value of _tCtrl.ToString() ?
// var val = Convert.ChangeType( _tCtrl.ToString(), tObj.GetType() );
// _tObj.SetValue( val );
}
}
Calling it would be like:
Class Bar
{
public Int32 _i { get; set; }
}
Bar bar = new Bar();
Foo foo = new Foo();
foo._tCtrl = new TextBox() { Text = "100" };
foo._tObj = bar._i;
foo.Set();
Or:
Foo foo = new Foo();
Int32 i;
foo._tCtrl = new TextBox() { Text = "100" };
foo._tObj = i;
foo.Set();
Anything could be passed into Set(). Assume that I can convert from a String to whatever type is tObj.GetType().
Stringto the type?Convert.ChangeType()for basic types, otherwise, I'll write a converter. I'm interested in how one would set the value to the object.