Mult() public static method

public static Mult ( Type maxType, object left, object right ) : object
maxType System.Type
left object
right object
return object
Esempio n. 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 multiplication 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.Mult(type, obj, obj2);
                }
            }
            return(result);
        }
Esempio n. 2
0
        /// <summary>
        /// Computes the product of the two args.
        /// Returns null if either arg is null
        /// or if either arg is not an integer
        /// </summary>
        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 multiplication 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.Mult(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 multiplication 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);
        }