Tuesday, November 16, 2004

Expose Single Bean

Again with Java-style Bean properties in .NET. Now I have a class to help one exposing Jave setter/getter as a .NET property.

For example, I have a bean:

public class Bean {
private string _name;
public string getName() {
return _name;
public void setName(string value) {
_name = value;

I can expose a single Bean to the Text property of a TextBox txtTestProp using the BeanDescriptor as follows:

Bean b = new Bean();
BeanDescriptor bd = new BeanDescriptor(b);
txtTestProp.DataBindings.Add("Text", bd, "Name");

No comments: