Beispiel #1
0
 private static List <NormalizedArrayIndex> TryGetOutOfRangeIndexes(
     NormalizedArrayPickIndex normalizedPickIndex,
     JArrayContext jArrayContext)
 {
     return(normalizedPickIndex
            .AllIndexes()
            .Where(index => IsIndexOutOfRange(
                       index.NormalizedValue,
                       jArrayContext))
            .ToList());
 }
Beispiel #2
0
        protected override Extraction ExtractFromJArray(
            JArrayContext jArrayContext)
        {
            var indexes = _pickIndexComposer.Compose(
                jArrayContext.Input,
                jArrayContext.Path);

            var normalizedPickIndex = NormalizedArrayPickIndex.Normalize(
                indexes: indexes,
                arrayLength: jArrayContext.Value.Count);

            var outOfRangeIndexes = TryGetOutOfRangeIndexes(
                normalizedPickIndex,
                jArrayContext);

            if (outOfRangeIndexes.Any())
            {
                return(IndexesOutOfRange(
                           jArrayContext,
                           outOfRangeIndexes));
            }

            var array = normalizedPickIndex
                        .AllIndexes()
                        .Aggregate(
                seed: new JArray(),
                (acc, index) =>
            {
                acc.Add(jArrayContext.Value[index.NormalizedValue]);
                return(acc);
            });

            if (indexes.Length == 1)
            {
                return(new CorrectExtraction(
                           GetPath(
                               jArrayContext.Path),
                           array[0]));
            }

            return(new CorrectExtraction(
                       GetPath(
                           jArrayContext.Path),
                       array));
        }