예제 #1
0
파일: JSONPatch.cs 프로젝트: ewertons/CBOR
 private static CBORObject RemoveOperation(
     CBORObject o,
     string valueOpStr,
     string path)
 {
     if (path == null)
     {
         throw new ArgumentException("Patch " + valueOpStr);
     }
     if (path.Length == 0)
     {
         return(o);
     }
     else
     {
         JSONPointer pointer = JSONPointer.FromPointer(o, path);
         if (!pointer.Exists())
         {
             throw new KeyNotFoundException("Patch " +
                                            valueOpStr + " " + path);
         }
         o = pointer.GetValue();
         if (pointer.GetParent().Type == CBORType.Array)
         {
             ((CBORObject)pointer.GetParent()).RemoveAt(pointer.GetIndex());
         }
         else if (pointer.GetParent().Type == CBORType.Map)
         {
             ((CBORObject)pointer.GetParent()).Remove(
                 CBORObject.FromObject(pointer.GetKey()));
         }
         return(o);
     }
 }
예제 #2
0
파일: JSONPatch.cs 프로젝트: ewertons/CBOR
 private static CBORObject ReplaceOperation(
     CBORObject o,
     string valueOpStr,
     string path,
     CBORObject value)
 {
     if (path == null)
     {
         throw new ArgumentException("Patch " + valueOpStr);
     }
     if (path.Length == 0)
     {
         o = value;
     }
     else
     {
         JSONPointer pointer = JSONPointer.FromPointer(o, path);
         if (!pointer.Exists())
         {
             throw new KeyNotFoundException("Patch " +
                                            valueOpStr + " " + path);
         }
         if (pointer.GetParent().Type == CBORType.Array)
         {
             int index = pointer.GetIndex();
             if (index < 0)
             {
                 throw new ArgumentException("Patch " + valueOpStr + " path");
             }
             ((CBORObject)pointer.GetParent()).Set(index, value);
         }
         else if (pointer.GetParent().Type == CBORType.Map)
         {
             string key = pointer.GetKey();
             ((CBORObject)pointer.GetParent()).Set(key, value);
         }
         else
         {
             throw new ArgumentException("Patch " + valueOpStr + " path");
         }
     }
     return(o);
 }