Attribute: [BindPropertyTo]
Posted by Gerhard Stephan on December 19th, 2006
The attribute BindPropertyTo is used to bind single properties or a collection to a specifc data type. This property is always required if you want to map a property with a not specified data type - like a property that returns an interface, an abstract class or a untyped collection.
Using the [BindPropertyTo] for that cases offers you a better performance, because the ObjectMapper .NET knows the target data type for the property and does not need to evaluate it dynamically.
Examples for using the BindPropertyTo attribute are:
private IList contacts = new ArrayList();
[BindPropertyTo(typeof(Contact))]
public IList Contacts
{
get { return contacts; }
set { contacts = value; }
}
or
private AbstractContact contact = new Contact();
[BindPropertyTo(typeof(Contact))]
public AbstractContact Contact
{
get { return contact; }
set { contact = value; }
}
or
private IContact contact = new Contact();
[BindPropertyTo(typeof(Contact))]
public IContact Contact
{
get { return contact; }
set { contact = value; }
}
Additionally you will find useful informations in blog entry How to do bind collections.
