Divan.CouchDocument.AutoReconcile C# (CSharp) Method

AutoReconcile() protected method

Automatically reconcile the database copy with the target instance. This method uses reflection to perform the reconcilliation, and as such won't perform as well as other version, but is available for low-occurance scenarios
protected AutoReconcile ( ICouchDocument databaseCopy ) : void
databaseCopy ICouchDocument
return void
        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;
        }