public virtual void Persist(object bindableObject, PropertyInfo pi, object control)
{
var d = control as DropDownList;
if (d == null) return;
if (!d.Enabled || !d.Visible) return;
var value = pi.GetValue(bindableObject, null);
if (value is IDomainObject)
{
var id = IdManager.New(d.SelectedValue);
// check if a BindScope is used
var items = BindManager.GetListFor(pi);
if (items != null)
{
var item = items.Cast<IDomainObject>().FirstOrDefault(o => o.Id == id);
if (item != null)
{
PropertyHelper.SetValue(bindableObject, pi, item);
return;
}
}
PropertyHelper.SetValue(bindableObject, pi, id);
}
else
{
PropertyHelper.SetValue(bindableObject, pi, d.SelectedValue);
}
}