// Calls the block on every attachment dictionary. The block can return a different dictionary,
 // which will be replaced in the rev's properties. If it returns nil, the operation aborts.
 // Returns YES if any changes were made.
 public virtual bool MutateAttachments(CollectionUtils.Functor<IDictionary<string, 
     object>, IDictionary<string, object>> functor)
 {
     {
         IDictionary<string, object> properties = GetProperties();
         IDictionary<string, object> editedProperties = null;
         IDictionary<string, object> attachments = (IDictionary<string, object>)properties
             .Get("_attachments");
         IDictionary<string, object> editedAttachments = null;
         foreach (string name in attachments.Keys)
         {
             IDictionary<string, object> attachment = (IDictionary<string, object>)attachments
                 .Get(name);
             IDictionary<string, object> editedAttachment = functor.Invoke(attachment);
             if (editedAttachment == null)
             {
                 return false;
             }
             // block canceled
             if (editedAttachment != attachment)
             {
                 if (editedProperties == null)
                 {
                     // Make the document properties and _attachments dictionary mutable:
                     editedProperties = new Dictionary<string, object>(properties);
                     editedAttachments = new Dictionary<string, object>(attachments);
                     editedProperties.Put("_attachments", editedAttachments);
                 }
                 editedAttachments.Put(name, editedAttachment);
             }
         }
         if (editedProperties != null)
         {
             SetProperties(editedProperties);
             return true;
         }
         return false;
     }
 }