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
Well, this is similar in tone to Hangy's solution, but is I think rather comfortable to use and does not require much magic:
public static Binding CreateTextBinding(this T source, Expression> access)
{
var mex = access.Body as MemberExpression;
string name = mex.Member.Name;
return new Binding("Text", source, name);
}
This is basically an extension method that can be called on any object acting as source. It gives you back a Binding for a Text property which you can add to any Bindings collection.