Ejemplo n.º 1
0
 public override dynamic Evaluate(SymbolTable table)
 {
     return(LeftNode.Evaluate(table) + RightNode.Evaluate(table));
 }
Ejemplo n.º 2
0
        public sealed override object Evaluate(NodeEvaluationContext evaluationContext)
        {
            var leftNodeValue  = LeftNode.Evaluate(evaluationContext);
            var rightNodeValue = RightNode.Evaluate(evaluationContext);

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

            var leftNodeValueType  = GetNodeValueType(leftNodeValue);
            var rightNodeValueType = GetNodeValueType(rightNodeValue);

            // determine the type to which we will need to widen any narrower value
            var maxNodeValueType = (NodeValueType)Math.Max((int)leftNodeValueType, (int)rightNodeValueType);

            // we have to convert rather than just cast because the value is boxed
            var convertibleLeftNodeValue  = leftNodeValue as IConvertible;
            var convertibleRightNodeValue = rightNodeValue as IConvertible;

            Debug.Assert(convertibleLeftNodeValue != null || (maxNodeValueType == NodeValueType.String || maxNodeValueType == NodeValueType.ReferenceType));
            Debug.Assert(convertibleRightNodeValue != null || (maxNodeValueType == NodeValueType.String || maxNodeValueType == NodeValueType.ReferenceType));

            var    succeeded = false;
            object result    = null;

            switch (maxNodeValueType)
            {
            case NodeValueType.String:
                succeeded = this.DoString(convertibleLeftNodeValue == null ? null : convertibleLeftNodeValue.ToString(null), convertibleRightNodeValue == null ? null : convertibleRightNodeValue.ToString(null), out result);
                break;

            case NodeValueType.Boolean:
                succeeded = this.DoBoolean(convertibleLeftNodeValue.ToBoolean(null), convertibleRightNodeValue.ToBoolean(null), out result);
                break;

            case NodeValueType.Byte:
                succeeded = this.DoByte(convertibleLeftNodeValue.ToByte(null), convertibleRightNodeValue.ToByte(null), out result);
                break;

            case NodeValueType.Int16:
                succeeded = this.DoInt16(convertibleLeftNodeValue.ToInt16(null), convertibleRightNodeValue.ToInt16(null), out result);
                break;

            case NodeValueType.Int32:
                succeeded = this.DoInt32(convertibleLeftNodeValue.ToInt32(null), convertibleRightNodeValue.ToInt32(null), out result);
                break;

            case NodeValueType.Int64:
                succeeded = this.DoInt64(convertibleLeftNodeValue.ToInt64(null), convertibleRightNodeValue.ToInt64(null), out result);
                break;

            case NodeValueType.Single:
                succeeded = this.DoSingle(convertibleLeftNodeValue.ToSingle(null), convertibleRightNodeValue.ToSingle(null), out result);
                break;

            case NodeValueType.Double:
                succeeded = this.DoDouble(convertibleLeftNodeValue.ToDouble(null), convertibleRightNodeValue.ToDouble(null), out result);
                break;

            case NodeValueType.Decimal:
                succeeded = this.DoDecimal(convertibleLeftNodeValue.ToDecimal(null), convertibleRightNodeValue.ToDecimal(null), out result);
                break;

            case NodeValueType.ValueType:
                succeeded = this.DoValueType(leftNodeValue, rightNodeValue, out result);
                break;

            case NodeValueType.ReferenceType:
                succeeded = this.DoReferenceType(leftNodeValue, rightNodeValue, out result);
                break;
            }

            exceptionHelper.ResolveAndThrowIf(!succeeded, "OperatorNotSupportedWithOperands", this.OperatorSymbols, leftNodeValueType, rightNodeValueType);
            return(result);
        }
Ejemplo n.º 3
0
 public override dynamic Evaluate(SymbolTable table)
 {
     return((LeftNode.GetType() == RightNode.GetType()) && (LeftNode.Evaluate(table) == RightNode.Evaluate(table)));
 }
Ejemplo n.º 4
0
 public override double Evaluate()
 {
     return(LeftNode.Evaluate() * RigthNode.Evaluate());
 }
Ejemplo n.º 5
0
 public override double Evaluate()
 {
     return(LeftNode.Evaluate() + RightNode.Evaluate());
 }
Ejemplo n.º 6
0
 public override dynamic Evaluate(SymbolTable table)
 {
     return((int)((uint)LeftNode.Evaluate(table) >> RightNode.Evaluate(table)));
 }