I have a simple class with a property
class Foo
{
string Title { get; set; }
}
I am trying to simplify data binding by calling a fun
Don't. Just modify the method to take another parameter, as described in #3444294. For your example, it may be something like this:
void BindToText(Control control, T dataSource, Expression> property)
{
var mex = property.Body as MemberExpression;
string name = mex.Member.Name;
control.DataBindings.Add("Text", dataSource, name);
}
and would be called like
BindToText(titleTextBox, foo, ()=>foo.Title );
Still nice, but easy to understand. There's no magic happening. ;)