Div() публичный статический Метод

public static Div ( Type maxType, object left, object right ) : object
maxType System.Type
left object
right object
Результат object
Пример #1
0
        /// <summary>
        /// Computes the result of the division. 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 division 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);
            }

            try
            {
                return(MathUtil.Div(maxType, left, right));
            }
            catch (DivideByZeroException)
            {
                runtimeServices.Error("Right side of division operation is zero. Must be non-zero. " + context.CurrentTemplateName + " [line " + Line + ", column " + Column + "]");
            }
            return(null);
        }
Пример #2
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 division 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.Div(type, obj, obj2);
                }
            }
            return(result);
        }