Esempio n. 1
0
 private static IEnumerable <Json> Function(
     List <IJsonMasherOperator> mashers, Json json, IMashContext context)
 {
     foreach (var value in mashers[1].Mash(json, context))
     {
         foreach (var pathAsJson in mashers[0].Mash(json, context))
         {
             var path = context.GetPathFromArray(pathAsJson);
             yield return(json.TransformByPath(
                              path,
                              leafJson => value,
                              (json, pathPart) => context.Error(
                                  $"Can't index {json.Type} with {pathPart.ToString()}.",
                                  json,
                                  pathPart.ToJson())));
         }
     }
 }
Esempio n. 2
0
        private static IEnumerable <Json> Function(
            List <IJsonMasherOperator> mashers, Json json, IMashContext context)
        {
            var result = new List <Json>();

            foreach (var pathAsJson in mashers[0].Mash(json, context))
            {
                var path = context.GetPathFromArray(pathAsJson);
                json.TransformByPath(
                    path,
                    leafJson => {
                    result.Add(leafJson);
                    return(leafJson);
                },
                    (json, pathPart) => context.Error(
                        $"Can't index {json.Type} with {pathPart.ToString()}.",
                        json,
                        pathPart.ToJson()));
            }
            return(result);
        }
Esempio n. 3
0
 private static IEnumerable <Json> Function(
     List <IJsonMasherOperator> mashers, Json json, IMashContext context)
 {
     foreach (var jsonPaths in mashers[0].Mash(json, context))
     {
         if (jsonPaths.Type != JsonValueType.Array)
         {
             throw context.Error($"Expected an array of paths.", jsonPaths);
         }
         var paths = jsonPaths
                     .EnumerateArray()
                     .OrderByDescending(x => x, JsonComparer.Instance)
                     .Select(x => context.GetPathFromArray(x));
         var jsonResult = json;
         foreach (var path in paths)
         {
             jsonResult = DeletePath(jsonResult, path, context);
         }
         yield return(jsonResult);
     }
 }