Пример #1
0
    public DirectiveNode ToNode(bool removeNullArguments)
    {
        if (_parsedDirective is null)
        {
            _parsedDirective = ParseValue(Type, _customDirective !);
        }

        if (removeNullArguments &&
            _parsedDirective.Arguments.Count != 0 &&
            _parsedDirective.Arguments.Any(t => t.Value.IsNull()))
        {
            var arguments = new List <ArgumentNode>();

            foreach (ArgumentNode argument in _parsedDirective.Arguments)
            {
                if (!argument.Value.IsNull())
                {
                    arguments.Add(argument);
                }
            }

            return(_parsedDirective.WithArguments(arguments));
        }

        return(_parsedDirective);
    }
Пример #2
0
        protected override DirectiveNode RewriteDirective(
            DirectiveNode node,
            string context)
        {
            if (node.Name.Value.EqualsOrdinal(DirectiveNames.Delegate) &&
                !node.Arguments.Any(a => a.Name.Value.EqualsOrdinal(
                                        DirectiveFieldNames.Delegate_Schema)))
            {
                var arguments = node.Arguments.ToList();

                arguments.Add(new ArgumentNode(
                                  DirectiveFieldNames.Delegate_Schema,
                                  context));

                return(node.WithArguments(arguments));
            }

            return(node);
        }
Пример #3
0
        public DirectiveNode ToNode(bool removeNullArguments)
        {
            if (_parsedDirective is null)
            {
                var  arguments = new List <ArgumentNode>();
                Type type      = _customDirective.GetType();
                ILookup <string, PropertyInfo> properties = type.GetProperties()
                                                            .ToLookup(t => t.Name, StringComparer.OrdinalIgnoreCase);

                foreach (Argument argument in Type.Arguments)
                {
                    PropertyInfo property =
                        properties[argument.Name].FirstOrDefault();
                    var value = property?.GetValue(_customDirective);

                    IValueNode valueNode = argument.Type.ParseValue(value);
                    arguments.Add(new ArgumentNode(argument.Name, valueNode));
                }

                _parsedDirective = new DirectiveNode(Name, arguments);
            }

            if (removeNullArguments &&
                _parsedDirective.Arguments.Count != 0 &&
                _parsedDirective.Arguments.Any(t => t.Value.IsNull()))
            {
                var arguments = new List <ArgumentNode>();
                foreach (ArgumentNode argument in _parsedDirective.Arguments)
                {
                    if (!argument.Value.IsNull())
                    {
                        arguments.Add(argument);
                    }
                }
                return(_parsedDirective.WithArguments(arguments));
            }

            return(_parsedDirective);
        }