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 modulus 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); } // 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 modulus 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; // } Type maxType = MathUtil.ToMaxType(left.GetType(), right.GetType()); if (maxType == null) { return(null); } return(MathUtil.Mod(maxType, left, right)); // check for divide by 0 // if (((Int32) right) == 0) // { // runtimeServices.Error("Right side of modulus operation is zero. Must be non-zero. " + context.CurrentTemplateName + " [line " + Line + ", column " + Column + "]"); // // return null; // } // // return ((Int32) left)%((Int32) right); }
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 modulus 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.Mod(type, obj, obj2); } } return(result); }