public override bool Evaluate(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 '<=' 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(false);
            }

            try
            {
                return(ObjectComparer.CompareObjects(left, right) <= 0);
            }
            catch (ArgumentException ae)
            {
                runtimeServices.Error(ae.Message);

                return(false);
            }
        }
Exemple #2
0
        public override bool Evaluate(IInternalContextAdapter context)
        {
            Object left  = GetChild(0).Value(context);
            Object right = GetChild(1).Value(context);

            try
            {
                return(ObjectComparer.CompareObjects(left, right) != 0);
            }
            catch
            {
                // Ignore, we can't compare decently by value, but we honestly don't give a sh*t
            }

            // If we can't actually compare the objects, try the operator as fallback
            // For operator overloaded types, this will not really be a reference comp, but that's ok.
            return(left != right);
        }
Exemple #3
0
        /// <summary>
        /// Calculates the value of the logical expression
        ///
        /// arg1 == arg2
        ///
        /// All class types are supported.   Uses equals() to
        /// determine equivalence.  This should work as we represent
        /// with the types we already support, and anything else that
        /// implements equals() to mean more than identical references.
        /// </summary>
        /// <param name="context"> internal context used to evaluate the LHS and RHS </param>
        /// <returns>
        /// true if equivalent, false if not equivalent,
        /// false if not compatible arguments, or false
        /// if either LHS or RHS is null
        /// </returns>
        public override bool Evaluate(IInternalContextAdapter context)
        {
            Object left  = GetChild(0).Value(context);
            Object right = GetChild(1).Value(context);

            // for equality, they are allowed to be null references
            try
            {
                if (ObjectComparer.CompareObjects(left, right) == 0)
                {
                    return(true);
                }
            }
            catch
            {
                // Ignore, we can't compare decently by value, but we honestly don't give a sh*t
            }

            // They are not equal by value, try a reference comparison
            // reference equal => definitely equal objects ;)
            // For operator overloaded types, this will not really be a reference comp, but that's ok.
            return(left == right);
        }