Exemplo n.º 1
0
            internal static bool TryCreateItemValue <ItemT>(
                PType <ItemT> itemType,
                string json,
                GreenJsonListSyntax jsonListSyntax,
                int itemIndex,
                int listSyntaxStartPosition,
                List <JsonErrorInfo> errors,
                out ItemT convertedTargetValue,
                out PValue value)
            {
                GreenJsonValueSyntax itemNode = jsonListSyntax.ListItemNodes[itemIndex].ValueNode.ContentNode;

                int itemNodeStart = listSyntaxStartPosition
                                    + jsonListSyntax.GetElementNodeStart(itemIndex)
                                    + jsonListSyntax.ListItemNodes[itemIndex].ValueNode.BackgroundBefore.Length;

                var itemValueOrError = itemType.TryCreateValue(
                    json,
                    itemNode,
                    out convertedTargetValue,
                    itemNodeStart,
                    errors);

                if (itemValueOrError.IsOption2(out value))
                {
                    return(true);
                }

                // Report type error at this index.
                itemValueOrError.IsOption1(out ITypeErrorBuilder itemTypeError);
                errors.Add(ValueTypeErrorAtItemIndex.Create(itemTypeError, itemIndex, itemNode, json, itemNodeStart));
                return(false);
            }