Beispiel #1
0
        public override object Evaluate(NodeEvaluationContext evaluationContext)
        {
            var value = Node.Evaluate(evaluationContext);

            if (value == DependencyProperty.UnsetValue)
            {
                return DependencyProperty.UnsetValue;
            }

            var nodeValueType = GetNodeValueType(value);

            switch (nodeValueType)
            {
                case NodeValueType.Byte:
                    return -1 * (byte)value;
                case NodeValueType.Int16:
                    return -1 * (short)value;
                case NodeValueType.Int32:
                    return -1 * (int)value;
                case NodeValueType.Int64:
                    return -1 * (long)value;
                case NodeValueType.Single:
                    return -1 * (float)value;
                case NodeValueType.Double:
                    return -1 * (double)value;
                case NodeValueType.Decimal:
                    return -1 * (decimal)value;
            }
            throw new ParseException("Operator '~' cannot be applied to operand of type '{0}'.".FormatArgs(nodeValueType));
            //throw exceptionHelper.Resolve("CannotNegateValue", nodeValueType);
        }
Beispiel #2
0
        public override object Evaluate(NodeEvaluationContext evaluationContext)
        {
            var value = Node.Evaluate(evaluationContext);

            if (value == DependencyProperty.UnsetValue)
            {
                return DependencyProperty.UnsetValue;
            }

            var nodeValueType = GetNodeValueType(value);
            if (!Node.IsIntegralNodeValueType(nodeValueType))
                throw new ParseException("Operator '~' cannot be applied to operand of type '{0}'.".FormatArgs(nodeValueType));
            //exceptionHelper.ResolveAndThrowIf(!Node.IsIntegralNodeValueType(nodeValueType), "NotIntegralType", nodeValueType);

            switch (nodeValueType)
            {
                case NodeValueType.Byte:
                    return ~((byte)value);
                case NodeValueType.Int16:
                    return ~((short)value);
                case NodeValueType.Int32:
                    return ~((int)value);
                case NodeValueType.Int64:
                    return ~((long)value);
            }

            Debug.Assert(false);
            return null;
        }
Beispiel #3
0
        public override object Evaluate(NodeEvaluationContext evaluationContext)
        {
            Debug.Assert(evaluationContext != null);
            if (!evaluationContext.HasArgument(this.index))
                throw new ParseException("No argument with index {0} has been supplied.".FormatArgs(this.index));

            //exceptionHelper.ResolveAndThrowIf(!evaluationContext.HasArgument(this.index), "ArgumentNotFound", this.index);

            // variable values are passed inside the context for each evaluation
            return evaluationContext.GetArgument(this.index);
        }
        public override sealed object Evaluate(NodeEvaluationContext evaluationContext)
        {
            var leftNodeValue = LeftNode.Evaluate(evaluationContext);

            if (leftNodeValue == DependencyProperty.UnsetValue)
            {
                return DependencyProperty.UnsetValue;
            }

            var leftNodeValueType = GetNodeValueType(leftNodeValue);

            if (leftNodeValueType == NodeValueType.Boolean)
            {
                // give base a chance to yield a result without evaluating the right node
                var result = this.DetermineResultPreRightEvaluation((bool)leftNodeValue);

                if (result.HasValue)
                {
                    return result.Value;
                }
            }

            var rightNodeValue = RightNode.Evaluate(evaluationContext);

            if (rightNodeValue == DependencyProperty.UnsetValue)
            {
                return DependencyProperty.UnsetValue;
            }

            var rightNodeValueType = GetNodeValueType(rightNodeValue);
            if (leftNodeValueType != NodeValueType.Boolean || rightNodeValueType != NodeValueType.Boolean)
                throw new ParseException("Operator '{0}' cannot be applied to operands of type '{1}' and '{2}' because at least one is non-boolean.".FormatArgs(this.OperatorSymbols, leftNodeValueType, rightNodeValueType));
            //exceptionHelper.ResolveAndThrowIf(leftNodeValueType != NodeValueType.Boolean || rightNodeValueType != NodeValueType.Boolean, "OperandsNotBoolean", this.OperatorSymbols, leftNodeValueType, rightNodeValueType);

            return this.DetermineResultPostRightEvaluation((bool)leftNodeValue, (bool)rightNodeValue);
        }
        public override object Evaluate(NodeEvaluationContext evaluationContext)
        {
            var firstNodeValue = this.FirstNode.Evaluate(evaluationContext);

            if (firstNodeValue == DependencyProperty.UnsetValue)
            {
                return DependencyProperty.UnsetValue;
            }

            var firstNodeValueType = GetNodeValueType(firstNodeValue);

            if (firstNodeValueType != NodeValueType.Boolean)
                throw new ParseException("Operator '{0}' requires that the first node be of type Boolean, but it is of type '{1}'.".FormatArgs(this.OperatorSymbols, firstNodeValueType));
            //exceptionHelper.ResolveAndThrowIf(firstNodeValueType != NodeValueType.Boolean, "FirstNodeMustBeBoolean", this.OperatorSymbols, firstNodeValueType);

            if ((bool)firstNodeValue)
            {
                return this.SecondNode.Evaluate(evaluationContext);
            }
            else
            {
                return this.ThirdNode.Evaluate(evaluationContext);
            }
        }
Beispiel #6
0
 public abstract object Evaluate(NodeEvaluationContext evaluationContext);