public Dictionary<string, string> ObjectToBindings(IData dataObject, Dictionary<string, object> bindings)
{
var errorMessages = new Dictionary<string, string>();
foreach (var fieldDescriptor in _dataTypeDescriptor.Fields)
{
var bindingName = GetBindingName(fieldDescriptor);
if (bindings.ContainsKey(bindingName))
{
var propertyInfo = dataObject.GetType().GetProperty(fieldDescriptor.Name);
Verify.IsNotNull(propertyInfo, "Missing property type '{0}' does not contain property '{1}'", dataObject.GetType(), fieldDescriptor.Name);
if (propertyInfo.CanRead)
{
var newValue = propertyInfo.GetValue(dataObject, null);
if (newValue == null && !fieldDescriptor.IsNullable)
{
var fieldType = fieldDescriptor.InstanceType;
if (fieldType == typeof(string) && fieldDescriptor.ForeignKeyReferenceTypeName == null)
{
newValue = "";
}
else
{
newValue = GetDefaultValue(fieldType);
}
}
try
{
bindings[bindingName] = newValue;
}
catch (Exception ex)
{
errorMessages.Add(bindingName, ex.Message);
}
}
}
}
if (_showPublicationStatusSelector &&
_dataTypeDescriptor.SuperInterfaces.Contains(typeof(IPublishControlled)))
{
var publishControlled = dataObject as IPublishControlled;
bindings[PublicationStatusBindingName] = publishControlled.PublicationStatus;
}
return errorMessages.Count > 0 ? errorMessages : null;
}