public Dictionary<string, string> BindingsToObject(Dictionary<string, object> bindings, IData dataObject)
{
var errorMessages = new Dictionary<string, string>();
foreach (var fieldDescriptor in _dataTypeDescriptor.Fields)
{
if (_readOnlyFields.Contains(fieldDescriptor.Name))
{
continue;
}
var bindingName = GetBindingName(fieldDescriptor);
if (!bindings.ContainsKey(bindingName))
{
Verify.That(fieldDescriptor.IsNullable, "Missing value for field '{0}'", fieldDescriptor.Name);
continue;
}
var propertyInfo = dataObject.GetType().GetProperty(fieldDescriptor.Name);
if (propertyInfo.CanWrite)
{
var newValue = bindings[bindingName];
if (newValue is string && (newValue as string) == "" && IsNullableStringReference(propertyInfo))
{
newValue = null;
}
try
{
newValue = ValueTypeConverter.Convert(newValue, propertyInfo.PropertyType);
propertyInfo.GetSetMethod().Invoke(dataObject, new[] { newValue });
}
catch (Exception ex)
{
errorMessages.Add(bindingName, ex.Message);
}
}
}
if (_showPublicationStatusSelector &&
_dataTypeDescriptor.SuperInterfaces.Contains(typeof(IPublishControlled)))
{
var publishControlled = dataObject as IPublishControlled;
publishControlled.PublicationStatus = (string)bindings[PublicationStatusBindingName];
}
if (errorMessages.Count > 0)
{
return errorMessages;
}
return null;
}