Пример #1
0
        // ----------------------------------------------------------------------------------------
        /// <!-- IfUnequal -->
        /// <summary>
        ///      Throws an exception if the two objects are not the same when they should be
        /// </summary>
        /// <param name="objA"></param>
        /// <param name="objB"></param>
        /// <param name="descrA"></param>
        /// <param name="descrB"></param>
        /// <param name="place"></param>
        /// <returns>returns true if they are equal</returns>
        public static bool IfUnequal(object objA, object objB, string descrA, string descrB, string place)
        {
            string message = "";
            bool   equal   = (objA == objB);


            if (!equal)
            {
                // ----------------------------------------------------------------------
                //  Inequality message
                // ----------------------------------------------------------------------
                if (objA == null)
                {
                    message = descrA + " is null and " + descrB + " is not at " + place;
                }
                else if (objB == null)
                {
                    message = descrB + " is null and " + descrA + " is not at " + place;
                }
                else
                {
                    message = descrA + " does not match " + descrB + " at " + place + "."
                              + "\r\n'" + objA.ToString() + "' != '" + objB.ToString() + "'";
                }
                ThrowMessage.A(new DataException(message));
            }


            return(equal);
        }
Пример #2
0
        // ----------------------------------------------------------------------------------------
        /// <!-- IfTooLong -->
        /// <summary>
        ///      Throws an exception if the string is too long
        /// </summary>
        /// <param name="str"></param>
        /// <param name="maxLength"></param>
        /// <returns>returns true if string is too long</returns>
        public static bool IfTooLong(string str, int maxLength)
        {
            bool tooLong = true;

            if (str != null && str.Length > maxLength)
            {
                ThrowMessage.A(new OverflowException("string too long: " + str.Length + ">" + maxLength));
            }
            else
            {
                tooLong = false;
            }
            return(tooLong);
        }
Пример #3
0
        // ----------------------------------------------------------------------------------------
        /// <!-- IfNull -->
        /// <summary>
        ///      Throws if the object is null and returns a boolean
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="message"></param>
        /// <returns>returns true if the object is null</returns>
        public static bool IfNull(object obj, string message)
        {
            bool isNull = true;

            if (obj == null)
            {
                ThrowMessage.A(new NoNullAllowedException(message));
            }
            else
            {
                isNull = false;
            }
            return(isNull);
        }
Пример #4
0
        // ----------------------------------------------------------------------------------------
        /// <!-- IfNullOrEmpty -->
        /// <summary>
        ///      Throws if the string is null or empty and returns a boolean
        /// </summary>
        /// <param name="str"></param>
        /// <param name="message">returns true if the string is null or empty</param>
        public static bool IfNullOrEmpty(string str, string message)
        {
            bool isBlank = true;

            if (string.IsNullOrEmpty(str))
            {
                ThrowMessage.A(new NoNullAllowedException(message));
            }
            else
            {
                isBlank = false;
            }
            return(isBlank);
        }
Пример #5
0
        // ----------------------------------------------------------------------------------------
        /// <!-- IfNotMatch -->
        /// <summary>
        ///      Throws if the string does not match the patter and returns a boolean
        /// </summary>
        /// <param name="str"></param>
        /// <param name="pattern"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        public static bool IfNotMatch(string str, string pattern, string message)
        {
            bool notMatch = true;

            if (!Regex.IsMatch(str, pattern))
            {
                ThrowMessage.A(new FormatException(message + ": " + str));
            }
            else
            {
                notMatch = false;
            }
            return(notMatch);
        }