Sub() public static method

public static Sub ( Type maxType, object left, object right ) : object
maxType System.Type
left object
right object
return object
Example #1
0
        public override object Value(IInternalContextAdapter context)
        {
            object obj  = base.GetChild(0).Value(context);
            object obj2 = base.GetChild(1).Value(context);
            object result;

            if (obj == null || obj2 == null)
            {
                this.rsvc.Error(string.Concat(new object[]
                {
                    (obj == null) ? "Left" : "Right",
                    " side (",
                    base.GetChild((obj == null) ? 0 : 1).Literal,
                    ") of subtraction operation has null value. Operation not possible. ",
                    context.CurrentTemplateName,
                    " [line ",
                    base.Line,
                    ", column ",
                    base.Column,
                    "]"
                }));
                result = null;
            }
            else
            {
                Type type = MathUtil.ToMaxType(obj.GetType(), obj2.GetType());
                if (type == null)
                {
                    result = null;
                }
                else
                {
                    result = MathUtil.Sub(type, obj, obj2);
                }
            }
            return(result);
        }
Example #2
0
        /// <summary>
        /// Computes the value of the subtraction.
        /// Currently limited to integers.
        /// </summary>
        /// <returns>Integer(value) or null</returns>
        public override Object Value(IInternalContextAdapter context)
        {
            // get the two args
            Object left  = GetChild(0).Value(context);
            Object right = GetChild(1).Value(context);

            // if either is null, lets log and bail
            if (left == null || right == null)
            {
                runtimeServices.Error(
                    string.Format(
                        "{0} side ({1}) of subtraction operation has null value. Operation not possible. {2} [line {3}, column {4}]",
                        (left == null ? "Left" : "Right"), GetChild((left == null ? 0 : 1)).Literal, context.CurrentTemplateName, Line,
                        Column));
                return(null);
            }

            Type maxType = MathUtil.ToMaxType(left.GetType(), right.GetType());

            if (maxType == null)
            {
                return(null);
            }

            return(MathUtil.Sub(maxType, left, right));

            // if not an Integer, not much we can do either
//			if (!(left is Int32) || !(right is Int32))
//			{
//				runtimeServices.Error((!(left is Int32) ? "Left" : "Right") + " side of subtraction operation is not a valid type. " + "Currently only integers (1,2,3...) and Integer type is supported. " + context.CurrentTemplateName + " [line " + Line + ", column " + Column + "]");
//
//				return null;
//			}
//
//			return ((Int32) left) - ((Int32) right);
        }