protected void AutoReconcile(ICouchDocument databaseCopy)
{
var properties = GetType().GetProperties(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
var fields = GetType().GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
foreach (var field in fields)
// if we haven't changed the field,
if (EqualFields(field.GetValue(sourceData), field.GetValue(this)))
field.SetValue(this, field.GetValue(databaseCopy));
foreach (var prop in properties)
if (!prop.CanWrite || prop.GetIndexParameters().Length > 0)
continue;
else if (EqualFields(prop.GetValue(sourceData, null), prop.GetValue(this, null)))
prop.SetValue(this, prop.GetValue(databaseCopy, null), null);
// this is non-negotiable
Rev = databaseCopy.Rev;
}