Exemplo n.º 1
0
 private static IList CreateList(ListType type)
 => (IList)Activator.CreateInstance(type.ToRuntimeType()) !;
Exemplo n.º 2
0
        private IList ParseList(
            IValueNode resultValue,
            ListType type,
            Path path,
            int stack,
            bool defaults,
            IInputField?field)
        {
            if (resultValue.Kind == SyntaxKind.ListValue)
            {
                IList list = CreateList(type);
                IReadOnlyList <IValueNode> items = ((ListValueNode)resultValue).Items;
                var   flatList    = !type.ElementType.IsListType();
                IType elementType = type.ElementType;

                if (flatList)
                {
                    for (var i = 0; i < items.Count; i++)
                    {
                        list.Add(ParseLiteralInternal(
                                     items[i],
                                     elementType,
                                     path.Append(i),
                                     stack,
                                     defaults,
                                     field));
                    }
                }
                else
                {
                    for (var i = 0; i < items.Count; i++)
                    {
                        IValueNode item     = items[i];
                        Path       itemPath = path.Append(i);

                        if (item.Kind != SyntaxKind.ListValue)
                        {
                            throw ParseNestedList_InvalidSyntaxKind(type, item.Kind, itemPath);
                        }

                        list.Add(ParseLiteralInternal(
                                     item,
                                     elementType,
                                     itemPath,
                                     stack,
                                     defaults,
                                     field));
                    }
                }

                return(list);
            }
            else
            {
                IList list = CreateList(type);
                list.Add(ParseLiteralInternal(
                             resultValue,
                             type.ElementType,
                             path.Append(0),
                             stack,
                             defaults, field));
                return(list);
            }
        }