コード例 #1
0
        private static bool?EvaluateDirective(
            this DirectiveNode directive,
            IVariableCollection variables)
        {
            if (directive == null)
            {
                return(null);
            }

            ArgumentNode argumentNode = directive.Arguments.SingleOrDefault();

            if (argumentNode == null)
            {
                throw new QueryException(new QueryError(
                                             $"The {directive.Name.Value} attribute is not valid."));
            }

            if (argumentNode.Value is BooleanValueNode b)
            {
                return(b.Value);
            }

            if (argumentNode.Value is VariableNode v)
            {
                return(variables.GetVariable <bool>(v.Name.Value));
            }

            throw new QueryException(new QueryError(
                                         $"The {directive.Name.Value} if-argument value has to be a 'Boolean'."));
        }
コード例 #2
0
        private static bool?EvaluateDirective(
            this DirectiveNode directive,
            IVariableCollection variables)
        {
            if (directive == null)
            {
                return(null);
            }

            ArgumentNode argumentNode = directive.Arguments.SingleOrDefault();

            if (argumentNode == null)
            {
                throw new QueryException(
                          ErrorBuilder.New()
                          .SetMessage(string.Format(
                                          CultureInfo.InvariantCulture,
                                          CoreResources
                                          .DirectiveCollectionExtensions_NotValid,
                                          directive.Name.Value))
                          .Build());
            }

            if (argumentNode.Value is BooleanValueNode b)
            {
                return(b.Value);
            }

            if (argumentNode.Value is VariableNode v)
            {
                return(variables.GetVariable <bool>(v.Name.Value));
            }

            throw new QueryException(
                      ErrorBuilder.New()
                      .SetMessage(string.Format(
                                      CultureInfo.InvariantCulture,
                                      CoreResources
                                      .DirectiveCollectionExtensions_IfNotBoolean,
                                      directive.Name.Value))
                      .Build());
        }
コード例 #3
0
        private static bool IsTrue(
            IVariableCollection variables,
            IValueNode value)
        {
            if (value is BooleanValueNode b)
            {
                return(b.Value);
            }

            if (value is VariableNode v)
            {
                return(variables.GetVariable <bool>(v.Name.Value));
            }

            // TODO: Resources
            throw new QueryException(
                      ErrorBuilder.New()
                      .SetMessage(
                          "The skip/include if-argument " +
                          "value has to be a 'Boolean'.")
                      .AddLocation(value)
                      .Build());
        }