public static bool CheckSingleProperty(object o, string testString, out string status_str)
        {
            Type type;
            Type type1;
            bool flag;

            status_str = null;
            if (o == null)
            {
                return(false);
            }
            string[] strArrays = PropertyTest.ParseString(testString, 2, "=><!");
            if ((int)strArrays.Length < 2)
            {
                status_str = string.Concat("invalid property string : ", testString);
                return(false);
            }
            bool flag1 = false;
            bool flag2 = false;
            bool flag3 = false;
            bool flag4 = false;

            if (testString.IndexOf("=") > 0)
            {
                flag1 = true;
            }
            else if (testString.IndexOf("!") > 0)
            {
                flag2 = true;
            }
            else if (testString.IndexOf(">") > 0)
            {
                flag3 = true;
            }
            else if (testString.IndexOf("<") > 0)
            {
                flag4 = true;
            }
            if (!flag1 && !flag3 && !flag4 && !flag2)
            {
                return(false);
            }
            string str = PropertyTest.ParseForKeywords(o, strArrays[0].Trim(), false, out type);

            if (type == null)
            {
                status_str = string.Concat(strArrays[0], " : ", str);
                return(false);
            }
            string str1 = PropertyTest.ParseForKeywords(o, strArrays[1].Trim(), false, out type1);

            if (type1 == null)
            {
                status_str = string.Concat(strArrays[1], " : ", str1);
                return(false);
            }
            int num  = 10;
            int num1 = 10;

            if (PropertyTest.IsNumeric(type) && str.StartsWith("0x"))
            {
                num = 16;
            }
            if (PropertyTest.IsNumeric(type1) && str1.StartsWith("0x"))
            {
                num1 = 16;
            }
            if (type1 == typeof(TimeSpan) || type == typeof(TimeSpan))
            {
                if (flag1)
                {
                    try
                    {
                        if (TimeSpan.Parse(str) == TimeSpan.Parse(str1))
                        {
                            flag = true;
                            return(flag);
                        }
                    }
                    catch
                    {
                        status_str = string.Concat("invalid timespan comparison : {0}", testString);
                    }
                }
                else if (flag2)
                {
                    try
                    {
                        if (TimeSpan.Parse(str) != TimeSpan.Parse(str1))
                        {
                            flag = true;
                            return(flag);
                        }
                    }
                    catch
                    {
                        status_str = string.Concat("invalid timespan comparison : {0}", testString);
                    }
                }
                else if (flag3)
                {
                    try
                    {
                        if (TimeSpan.Parse(str) > TimeSpan.Parse(str1))
                        {
                            flag = true;
                            return(flag);
                        }
                    }
                    catch
                    {
                        status_str = string.Concat("invalid timespan comparison : {0}", testString);
                    }
                }
                else if (flag4)
                {
                    try
                    {
                        if (TimeSpan.Parse(str) < TimeSpan.Parse(str1))
                        {
                            flag = true;
                            return(flag);
                        }
                    }
                    catch
                    {
                        status_str = string.Concat("invalid timespan comparison : {0}", testString);
                    }
                }
            }
            else if (type1 == typeof(DateTime) || type == typeof(DateTime))
            {
                if (flag1)
                {
                    try
                    {
                        if (DateTime.Parse(str) == DateTime.Parse(str1))
                        {
                            flag = true;
                            return(flag);
                        }
                    }
                    catch
                    {
                        status_str = string.Concat("invalid DateTime comparison : {0}", testString);
                    }
                }
                else if (flag2)
                {
                    try
                    {
                        if (DateTime.Parse(str) != DateTime.Parse(str1))
                        {
                            flag = true;
                            return(flag);
                        }
                    }
                    catch
                    {
                        status_str = string.Concat("invalid DateTime comparison : {0}", testString);
                    }
                }
                else if (flag3)
                {
                    try
                    {
                        if (DateTime.Parse(str) > DateTime.Parse(str1))
                        {
                            flag = true;
                            return(flag);
                        }
                    }
                    catch
                    {
                        status_str = string.Concat("invalid DateTime comparison : {0}", testString);
                    }
                }
                else if (flag4)
                {
                    try
                    {
                        if (DateTime.Parse(str) < DateTime.Parse(str1))
                        {
                            flag = true;
                            return(flag);
                        }
                    }
                    catch
                    {
                        status_str = string.Concat("invalid DateTime comparison : {0}", testString);
                    }
                }
            }
            else if (PropertyTest.IsNumeric(type1) && PropertyTest.IsNumeric(type))
            {
                if (flag1)
                {
                    try
                    {
                        if (Convert.ToInt64(str, num) == Convert.ToInt64(str1, num1))
                        {
                            flag = true;
                            return(flag);
                        }
                    }
                    catch
                    {
                        status_str = string.Concat("invalid int comparison : {0}", testString);
                    }
                }
                else if (flag2)
                {
                    try
                    {
                        if (Convert.ToInt64(str, num) != Convert.ToInt64(str1, num1))
                        {
                            flag = true;
                            return(flag);
                        }
                    }
                    catch
                    {
                        status_str = string.Concat("invalid int comparison : {0}", testString);
                    }
                }
                else if (flag3)
                {
                    try
                    {
                        if (Convert.ToInt64(str, num) > Convert.ToInt64(str1, num1))
                        {
                            flag = true;
                            return(flag);
                        }
                    }
                    catch
                    {
                        status_str = string.Concat("invalid int comparison : {0}", testString);
                    }
                }
                else if (flag4)
                {
                    try
                    {
                        if (Convert.ToInt64(str, num) < Convert.ToInt64(str1, num1))
                        {
                            flag = true;
                            return(flag);
                        }
                    }
                    catch
                    {
                        status_str = string.Concat("invalid int comparison : {0}", testString);
                    }
                }
            }
            else if (type1 == typeof(double) && PropertyTest.IsNumeric(type))
            {
                if (flag1)
                {
                    try
                    {
                        if ((double)Convert.ToInt64(str, num) == double.Parse(str1))
                        {
                            flag = true;
                            return(flag);
                        }
                    }
                    catch
                    {
                        status_str = string.Concat("invalid int comparison : {0}", testString);
                    }
                }
                else if (flag2)
                {
                    try
                    {
                        if ((double)Convert.ToInt64(str, num) != double.Parse(str1))
                        {
                            flag = true;
                            return(flag);
                        }
                    }
                    catch
                    {
                        status_str = string.Concat("invalid int comparison : {0}", testString);
                    }
                }
                else if (flag3)
                {
                    try
                    {
                        if ((double)Convert.ToInt64(str, num) > double.Parse(str1))
                        {
                            flag = true;
                            return(flag);
                        }
                    }
                    catch
                    {
                        status_str = string.Concat("invalid int comparison : {0}", testString);
                    }
                }
                else if (flag4)
                {
                    try
                    {
                        if ((double)Convert.ToInt64(str, num) < double.Parse(str1))
                        {
                            flag = true;
                            return(flag);
                        }
                    }
                    catch
                    {
                        status_str = string.Concat("invalid int comparison : {0}", testString);
                    }
                }
            }
            else if (type == typeof(double) && PropertyTest.IsNumeric(type1))
            {
                if (flag1)
                {
                    try
                    {
                        if (double.Parse(str) == (double)Convert.ToInt64(str1, num1))
                        {
                            flag = true;
                            return(flag);
                        }
                    }
                    catch
                    {
                        status_str = string.Concat("invalid int comparison : {0}", testString);
                    }
                }
                else if (flag2)
                {
                    try
                    {
                        if (double.Parse(str) != (double)Convert.ToInt64(str1, num1))
                        {
                            flag = true;
                            return(flag);
                        }
                    }
                    catch
                    {
                        status_str = string.Concat("invalid int comparison : {0}", testString);
                    }
                }
                else if (flag3)
                {
                    try
                    {
                        if (double.Parse(str) > (double)Convert.ToInt64(str1, num1))
                        {
                            flag = true;
                            return(flag);
                        }
                    }
                    catch
                    {
                        status_str = string.Concat("invalid int comparison : {0}", testString);
                    }
                }
                else if (flag4)
                {
                    try
                    {
                        if (double.Parse(str) < (double)Convert.ToInt64(str1, num1))
                        {
                            flag = true;
                            return(flag);
                        }
                    }
                    catch
                    {
                        status_str = string.Concat("invalid int comparison : {0}", testString);
                    }
                }
            }
            else if (type == typeof(double) && type1 == typeof(double))
            {
                if (flag1)
                {
                    try
                    {
                        if (double.Parse(str) == double.Parse(str1))
                        {
                            flag = true;
                            return(flag);
                        }
                    }
                    catch
                    {
                        status_str = string.Concat("invalid int comparison : {0}", testString);
                    }
                }
                else if (flag2)
                {
                    try
                    {
                        if (double.Parse(str) != double.Parse(str1))
                        {
                            flag = true;
                            return(flag);
                        }
                    }
                    catch
                    {
                        status_str = string.Concat("invalid int comparison : {0}", testString);
                    }
                }
                else if (flag3)
                {
                    try
                    {
                        if (double.Parse(str) > double.Parse(str1))
                        {
                            flag = true;
                            return(flag);
                        }
                    }
                    catch
                    {
                        status_str = string.Concat("invalid int comparison : {0}", testString);
                    }
                }
                else if (flag4)
                {
                    try
                    {
                        if (double.Parse(str) < double.Parse(str1))
                        {
                            flag = true;
                            return(flag);
                        }
                    }
                    catch
                    {
                        status_str = string.Concat("invalid int comparison : {0}", testString);
                    }
                }
            }
            else if (type1 == typeof(bool) && type == typeof(bool))
            {
                try
                {
                    if (Convert.ToBoolean(str) == Convert.ToBoolean(str1))
                    {
                        flag = true;
                        return(flag);
                    }
                }
                catch
                {
                    status_str = string.Concat("invalid bool comparison : {0}", testString);
                }
            }
            else if (type1 != typeof(double) && type1 != typeof(double))
            {
                if (flag1)
                {
                    if (str == str1)
                    {
                        return(true);
                    }
                }
                else if (flag2 && str != str1)
                {
                    return(true);
                }
            }
            else if (flag1)
            {
                try
                {
                    if (Convert.ToDouble(str) == Convert.ToDouble(str1))
                    {
                        flag = true;
                        return(flag);
                    }
                }
                catch
                {
                    status_str = string.Concat("invalid double comparison : {0}", testString);
                }
            }
            else if (flag2)
            {
                try
                {
                    if (Convert.ToDouble(str) != Convert.ToDouble(str1))
                    {
                        flag = true;
                        return(flag);
                    }
                }
                catch
                {
                    status_str = string.Concat("invalid double comparison : {0}", testString);
                }
            }
            else if (flag3)
            {
                try
                {
                    if (Convert.ToDouble(str) > Convert.ToDouble(str1))
                    {
                        flag = true;
                        return(flag);
                    }
                }
                catch
                {
                    status_str = string.Concat("invalid double comparison : {0}", testString);
                }
            }
            else if (flag4)
            {
                try
                {
                    if (Convert.ToDouble(str) < Convert.ToDouble(str1))
                    {
                        flag = true;
                        return(flag);
                    }
                }
                catch
                {
                    status_str = string.Concat("invalid double comparison : {0}", testString);
                }
            }
            return(false);
        }
Exemple #2
0
        public static bool CheckSingleProperty(object o, string testString, out string status_str)
        {
            status_str = (string)null;
            if (o == null)
            {
                return(false);
            }
            string[] strArray = PropertyTest.ParseString(testString, 2, "=><!");
            if (strArray.Length < 2)
            {
                status_str = "invalid property string : " + testString;
                return(false);
            }
            bool flag1 = false;
            bool flag2 = false;
            bool flag3 = false;
            bool flag4 = false;

            if (testString.IndexOf("=") > 0)
            {
                flag1 = true;
            }
            else if (testString.IndexOf("!") > 0)
            {
                flag2 = true;
            }
            else if (testString.IndexOf(">") > 0)
            {
                flag3 = true;
            }
            else if (testString.IndexOf("<") > 0)
            {
                flag4 = true;
            }
            if (!flag1 && !flag3 && (!flag4 && !flag2))
            {
                return(false);
            }
            Type   ptype1;
            string s1 = PropertyTest.ParseForKeywords(o, strArray[0].Trim(), false, out ptype1);

            if (ptype1 == null)
            {
                status_str = strArray[0] + " : " + s1;
                return(false);
            }
            Type   ptype2;
            string s2 = PropertyTest.ParseForKeywords(o, strArray[1].Trim(), false, out ptype2);

            if (ptype2 == null)
            {
                status_str = strArray[1] + " : " + s2;
                return(false);
            }
            int fromBase1 = 10;
            int fromBase2 = 10;

            if (PropertyTest.IsNumeric(ptype1) && s1.StartsWith("0x"))
            {
                fromBase1 = 16;
            }
            if (PropertyTest.IsNumeric(ptype2) && s2.StartsWith("0x"))
            {
                fromBase2 = 16;
            }
            if (ptype2 == typeof(TimeSpan) || ptype1 == typeof(TimeSpan))
            {
                if (flag1)
                {
                    try
                    {
                        if (TimeSpan.Parse(s1) == TimeSpan.Parse(s2))
                        {
                            return(true);
                        }
                    }
                    catch
                    {
                        status_str = "invalid timespan comparison : {0}" + testString;
                    }
                }
                else if (flag2)
                {
                    try
                    {
                        if (TimeSpan.Parse(s1) != TimeSpan.Parse(s2))
                        {
                            return(true);
                        }
                    }
                    catch
                    {
                        status_str = "invalid timespan comparison : {0}" + testString;
                    }
                }
                else if (flag3)
                {
                    try
                    {
                        if (TimeSpan.Parse(s1) > TimeSpan.Parse(s2))
                        {
                            return(true);
                        }
                    }
                    catch
                    {
                        status_str = "invalid timespan comparison : {0}" + testString;
                    }
                }
                else if (flag4)
                {
                    try
                    {
                        if (TimeSpan.Parse(s1) < TimeSpan.Parse(s2))
                        {
                            return(true);
                        }
                    }
                    catch
                    {
                        status_str = "invalid timespan comparison : {0}" + testString;
                    }
                }
            }
            else if (ptype2 == typeof(DateTime) || ptype1 == typeof(DateTime))
            {
                if (flag1)
                {
                    try
                    {
                        if (DateTime.Parse(s1) == DateTime.Parse(s2))
                        {
                            return(true);
                        }
                    }
                    catch
                    {
                        status_str = "invalid DateTime comparison : {0}" + testString;
                    }
                }
                else if (flag2)
                {
                    try
                    {
                        if (DateTime.Parse(s1) != DateTime.Parse(s2))
                        {
                            return(true);
                        }
                    }
                    catch
                    {
                        status_str = "invalid DateTime comparison : {0}" + testString;
                    }
                }
                else if (flag3)
                {
                    try
                    {
                        if (DateTime.Parse(s1) > DateTime.Parse(s2))
                        {
                            return(true);
                        }
                    }
                    catch
                    {
                        status_str = "invalid DateTime comparison : {0}" + testString;
                    }
                }
                else if (flag4)
                {
                    try
                    {
                        if (DateTime.Parse(s1) < DateTime.Parse(s2))
                        {
                            return(true);
                        }
                    }
                    catch
                    {
                        status_str = "invalid DateTime comparison : {0}" + testString;
                    }
                }
            }
            else if (PropertyTest.IsNumeric(ptype2) && PropertyTest.IsNumeric(ptype1))
            {
                if (flag1)
                {
                    try
                    {
                        if (Convert.ToInt64(s1, fromBase1) == Convert.ToInt64(s2, fromBase2))
                        {
                            return(true);
                        }
                    }
                    catch
                    {
                        status_str = "invalid int comparison : {0}" + testString;
                    }
                }
                else if (flag2)
                {
                    try
                    {
                        if (Convert.ToInt64(s1, fromBase1) != Convert.ToInt64(s2, fromBase2))
                        {
                            return(true);
                        }
                    }
                    catch
                    {
                        status_str = "invalid int comparison : {0}" + testString;
                    }
                }
                else if (flag3)
                {
                    try
                    {
                        if (Convert.ToInt64(s1, fromBase1) > Convert.ToInt64(s2, fromBase2))
                        {
                            return(true);
                        }
                    }
                    catch
                    {
                        status_str = "invalid int comparison : {0}" + testString;
                    }
                }
                else if (flag4)
                {
                    try
                    {
                        if (Convert.ToInt64(s1, fromBase1) < Convert.ToInt64(s2, fromBase2))
                        {
                            return(true);
                        }
                    }
                    catch
                    {
                        status_str = "invalid int comparison : {0}" + testString;
                    }
                }
            }
            else if (ptype2 == typeof(double) && PropertyTest.IsNumeric(ptype1))
            {
                if (flag1)
                {
                    try
                    {
                        if ((double)Convert.ToInt64(s1, fromBase1) == double.Parse(s2))
                        {
                            return(true);
                        }
                    }
                    catch
                    {
                        status_str = "invalid int comparison : {0}" + testString;
                    }
                }
                else if (flag2)
                {
                    try
                    {
                        if ((double)Convert.ToInt64(s1, fromBase1) != double.Parse(s2))
                        {
                            return(true);
                        }
                    }
                    catch
                    {
                        status_str = "invalid int comparison : {0}" + testString;
                    }
                }
                else if (flag3)
                {
                    try
                    {
                        if ((double)Convert.ToInt64(s1, fromBase1) > double.Parse(s2))
                        {
                            return(true);
                        }
                    }
                    catch
                    {
                        status_str = "invalid int comparison : {0}" + testString;
                    }
                }
                else if (flag4)
                {
                    try
                    {
                        if ((double)Convert.ToInt64(s1, fromBase1) < double.Parse(s2))
                        {
                            return(true);
                        }
                    }
                    catch
                    {
                        status_str = "invalid int comparison : {0}" + testString;
                    }
                }
            }
            else if (ptype1 == typeof(double) && PropertyTest.IsNumeric(ptype2))
            {
                if (flag1)
                {
                    try
                    {
                        if (double.Parse(s1) == (double)Convert.ToInt64(s2, fromBase2))
                        {
                            return(true);
                        }
                    }
                    catch
                    {
                        status_str = "invalid int comparison : {0}" + testString;
                    }
                }
                else if (flag2)
                {
                    try
                    {
                        if (double.Parse(s1) != (double)Convert.ToInt64(s2, fromBase2))
                        {
                            return(true);
                        }
                    }
                    catch
                    {
                        status_str = "invalid int comparison : {0}" + testString;
                    }
                }
                else if (flag3)
                {
                    try
                    {
                        if (double.Parse(s1) > (double)Convert.ToInt64(s2, fromBase2))
                        {
                            return(true);
                        }
                    }
                    catch
                    {
                        status_str = "invalid int comparison : {0}" + testString;
                    }
                }
                else if (flag4)
                {
                    try
                    {
                        if (double.Parse(s1) < (double)Convert.ToInt64(s2, fromBase2))
                        {
                            return(true);
                        }
                    }
                    catch
                    {
                        status_str = "invalid int comparison : {0}" + testString;
                    }
                }
            }
            else if (ptype1 == typeof(double) && ptype2 == typeof(double))
            {
                if (flag1)
                {
                    try
                    {
                        if (double.Parse(s1) == double.Parse(s2))
                        {
                            return(true);
                        }
                    }
                    catch
                    {
                        status_str = "invalid int comparison : {0}" + testString;
                    }
                }
                else if (flag2)
                {
                    try
                    {
                        if (double.Parse(s1) != double.Parse(s2))
                        {
                            return(true);
                        }
                    }
                    catch
                    {
                        status_str = "invalid int comparison : {0}" + testString;
                    }
                }
                else if (flag3)
                {
                    try
                    {
                        if (double.Parse(s1) > double.Parse(s2))
                        {
                            return(true);
                        }
                    }
                    catch
                    {
                        status_str = "invalid int comparison : {0}" + testString;
                    }
                }
                else if (flag4)
                {
                    try
                    {
                        if (double.Parse(s1) < double.Parse(s2))
                        {
                            return(true);
                        }
                    }
                    catch
                    {
                        status_str = "invalid int comparison : {0}" + testString;
                    }
                }
            }
            else
            {
                if (ptype2 == typeof(bool))
                {
                    if (ptype1 == typeof(bool))
                    {
                        try
                        {
                            if (Convert.ToBoolean(s1) == Convert.ToBoolean(s2))
                            {
                                return(true);
                            }
                            goto label_151;
                        }
                        catch
                        {
                            status_str = "invalid bool comparison : {0}" + testString;
                            goto label_151;
                        }
                    }
                }
                if (ptype2 == typeof(double) || ptype2 == typeof(double))
                {
                    if (flag1)
                    {
                        try
                        {
                            if (Convert.ToDouble(s1) == Convert.ToDouble(s2))
                            {
                                return(true);
                            }
                        }
                        catch
                        {
                            status_str = "invalid double comparison : {0}" + testString;
                        }
                    }
                    else if (flag2)
                    {
                        try
                        {
                            if (Convert.ToDouble(s1) != Convert.ToDouble(s2))
                            {
                                return(true);
                            }
                        }
                        catch
                        {
                            status_str = "invalid double comparison : {0}" + testString;
                        }
                    }
                    else if (flag3)
                    {
                        try
                        {
                            if (Convert.ToDouble(s1) > Convert.ToDouble(s2))
                            {
                                return(true);
                            }
                        }
                        catch
                        {
                            status_str = "invalid double comparison : {0}" + testString;
                        }
                    }
                    else if (flag4)
                    {
                        try
                        {
                            if (Convert.ToDouble(s1) < Convert.ToDouble(s2))
                            {
                                return(true);
                            }
                        }
                        catch
                        {
                            status_str = "invalid double comparison : {0}" + testString;
                        }
                    }
                }
                else if (flag1)
                {
                    if (s1 == s2)
                    {
                        return(true);
                    }
                }
                else if (flag2 && s1 != s2)
                {
                    return(true);
                }
            }
label_151:
            return(false);
        }