public static ArraySegment <byte> SerializeMetadataPropertyBag(SaveWorkflowCommand saveWorkflowCommand, InstancePersistenceContext context, InstanceEncodingOption instanceEncodingOption)
        {
            IObjectSerializer          objectSerializer = ObjectSerializerFactory.GetObjectSerializer(instanceEncodingOption);
            Dictionary <XName, object> dictionary       = new Dictionary <XName, object>();

            if (context.InstanceView.InstanceMetadataConsistency == InstanceValueConsistency.None)
            {
                foreach (KeyValuePair <XName, InstanceValue> pair in context.InstanceView.InstanceMetadata)
                {
                    if ((pair.Value.Options & InstanceValueOptions.WriteOnly) == InstanceValueOptions.None)
                    {
                        dictionary.Add(pair.Key, pair.Value.Value);
                    }
                }
            }
            foreach (KeyValuePair <XName, InstanceValue> pair2 in saveWorkflowCommand.InstanceMetadataChanges)
            {
                if (pair2.Value.IsDeletedValue)
                {
                    if (context.InstanceView.InstanceMetadataConsistency == InstanceValueConsistency.None)
                    {
                        dictionary.Remove(pair2.Key);
                    }
                    else
                    {
                        DeletedMetadataValue value2 = new DeletedMetadataValue();
                        dictionary[pair2.Key] = value2;
                    }
                }
                else if ((pair2.Value.Options & InstanceValueOptions.WriteOnly) == InstanceValueOptions.None)
                {
                    dictionary[pair2.Key] = pair2.Value.Value;
                }
            }
            if (dictionary.Count > 0)
            {
                return(objectSerializer.SerializePropertyBag(dictionary));
            }
            return(new ArraySegment <byte>());
        }
 public static ArraySegment<byte> SerializeMetadataPropertyBag(SaveWorkflowCommand saveWorkflowCommand, InstancePersistenceContext context, InstanceEncodingOption instanceEncodingOption)
 {
     IObjectSerializer objectSerializer = ObjectSerializerFactory.GetObjectSerializer(instanceEncodingOption);
     Dictionary<XName, object> dictionary = new Dictionary<XName, object>();
     if (context.InstanceView.InstanceMetadataConsistency == InstanceValueConsistency.None)
     {
         foreach (KeyValuePair<XName, InstanceValue> pair in context.InstanceView.InstanceMetadata)
         {
             if ((pair.Value.Options & InstanceValueOptions.WriteOnly) == InstanceValueOptions.None)
             {
                 dictionary.Add(pair.Key, pair.Value.Value);
             }
         }
     }
     foreach (KeyValuePair<XName, InstanceValue> pair2 in saveWorkflowCommand.InstanceMetadataChanges)
     {
         if (pair2.Value.IsDeletedValue)
         {
             if (context.InstanceView.InstanceMetadataConsistency == InstanceValueConsistency.None)
             {
                 dictionary.Remove(pair2.Key);
             }
             else
             {
                 DeletedMetadataValue value2 = new DeletedMetadataValue();
                 dictionary[pair2.Key] = value2;
             }
         }
         else if ((pair2.Value.Options & InstanceValueOptions.WriteOnly) == InstanceValueOptions.None)
         {
             dictionary[pair2.Key] = pair2.Value.Value;
         }
     }
     if (dictionary.Count > 0)
     {
         return objectSerializer.SerializePropertyBag(dictionary);
     }
     return new ArraySegment<byte>();
 }