コード例 #1
0
        private static string InternalGetValue(object o, PropertyInfo p, int index)
        {
            Type   propertyType = p.PropertyType;
            object obj1         = (object)null;

            if (propertyType.IsArray)
            {
                try
                {
                    object obj2       = p.GetValue(o, (object[])null);
                    int    lowerBound = ((Array)obj2).GetLowerBound(0);
                    int    upperBound = ((Array)obj2).GetUpperBound(0);
                    if (index <= lowerBound)
                    {
                        if (index <= upperBound)
                        {
                            obj1 = ((Array)obj2).GetValue(index);
                        }
                    }
                }
                catch
                {
                }
            }
            else
            {
                obj1 = p.GetValue(o, (object[])null);
            }
            string str = obj1 != null ? (!PropertyTest.IsNumeric(propertyType) ? (!PropertyTest.IsChar(propertyType) ? (!PropertyTest.IsString(propertyType) ? obj1.ToString() : string.Format("\"{0}\"", obj1)) : string.Format("'{0}' ({1} [0x{1:X}])", obj1, (object)(int)obj1)) : string.Format("{0} (0x{0:X})", obj1)) : "(-null-)";

            return(string.Format("{0} = {1}", (object)p.Name, (object)str));
        }
コード例 #2
0
        public static string ParseForKeywords(object o, string valstr, bool literal, out Type ptype)
        {
            ptype = (Type)null;
            if (valstr == null || valstr.Length <= 0)
            {
                return((string)null);
            }
            string str1 = valstr.Trim();

            string[] strArray1 = PropertyTest.ParseString(str1, 2, "[");
            string   str2      = (string)null;

            if (strArray1.Length > 1)
            {
                str2 = PropertyTest.ParseToMatchingParen(strArray1[1], '[', ']')[0];
            }
            string[] strArray2 = strArray1[0].Trim().Split(',');
            if (str2 != null && str2.Length > 0 && (strArray2 != null && strArray2.Length > 0))
            {
                strArray2[strArray2.Length - 1] = str2;
            }
            string name = strArray2[0].Trim();
            char   ch   = str1[0];

            if ((int)ch == 46 || (int)ch == 45 || (int)ch == 43 || (int)ch >= 48 && (int)ch <= 57)
            {
                ptype = str1.IndexOf(".") < 0 ? typeof(int) : typeof(double);
                return(str1);
            }
            if ((int)ch == 34 || (int)ch == 40)
            {
                ptype = typeof(string);
                return(str1);
            }
            if ((int)ch == 35)
            {
                ptype = typeof(string);
                return(str1.Substring(1));
            }
            if (str1.ToLower() == "true" || str1.ToLower() == "false")
            {
                ptype = typeof(bool);
                return(str1);
            }
            if (!literal)
            {
                return(PropertyTest.ParseGetValue(PropertyTest.GetPropertyValue(o, name, out ptype), ptype));
            }
            ptype = typeof(string);
            return(str1);
        }
コード例 #3
0
 public static string ParseGetValue(string str, Type ptype)
 {
     if (str == null)
     {
         return((string)null);
     }
     string[] strArray = str.Split("=".ToCharArray(), 2);
     if (strArray.Length <= 1)
     {
         return((string)null);
     }
     if (PropertyTest.IsNumeric(ptype))
     {
         return(strArray[1].Trim().Split(" ".ToCharArray(), 2)[0]);
     }
     return(strArray[1].Trim());
 }
コード例 #4
0
 public static string ParseGetValue(string str, Type ptype)
 {
     if (str == null)
     {
         return(null);
     }
     string[] strArrays = str.Split("=".ToCharArray(), 2);
     if ((int)strArrays.Length <= 1)
     {
         return(null);
     }
     if (!PropertyTest.IsNumeric(ptype))
     {
         return(strArrays[1].Trim());
     }
     string[] strArrays1 = strArrays[1].Trim().Split(" ".ToCharArray(), 2);
     return(strArrays1[0]);
 }
コード例 #5
0
        private static string InternalGetValue(object o, PropertyInfo p, int index)
        {
            string str;
            Type   propertyType = p.PropertyType;
            object value        = null;

            if (!propertyType.IsArray)
            {
                value = p.GetValue(o, null);
            }
            else
            {
                try
                {
                    object obj        = p.GetValue(o, null);
                    int    lowerBound = ((Array)obj).GetLowerBound(0);
                    int    upperBound = ((Array)obj).GetUpperBound(0);
                    if (index <= lowerBound && index <= upperBound)
                    {
                        value = ((Array)obj).GetValue(index);
                    }
                }
                catch
                {
                }
            }
            if (value == null)
            {
                str = "(-null-)";
            }
            else if (PropertyTest.IsNumeric(propertyType))
            {
                str = string.Format("{0} (0x{0:X})", value);
            }
            else if (!PropertyTest.IsChar(propertyType))
            {
                str = (!PropertyTest.IsString(propertyType) ? value.ToString() : string.Format("\"{0}\"", value));
            }
            else
            {
                str = string.Format("'{0}' ({1} [0x{1:X}])", value, (int)value);
            }
            return(string.Format("{0} = {1}", p.Name, str));
        }
コード例 #6
0
        public static bool CheckPropertyString(object o, string testString, out string status_str)
        {
            status_str = null;
            if (o == null)
            {
                return(false);
            }
            if (testString == null || testString.Length < 1)
            {
                status_str = "Null property test string";
                return(false);
            }
            string[] strArrays = PropertyTest.ParseString(testString, 2, "&|");
            if ((int)strArrays.Length < 2)
            {
                return(PropertyTest.CheckSingleProperty(o, testString, out status_str));
            }
            bool flag  = PropertyTest.CheckSingleProperty(o, strArrays[0], out status_str);
            bool flag1 = PropertyTest.CheckPropertyString(o, strArrays[1], out status_str);
            int  num   = testString.IndexOf("&");
            int  num1  = testString.IndexOf("|");

            if (num > 0 && num1 <= 0 || num > 0 && num < num1)
            {
                if (flag)
                {
                    return(flag1);
                }
                return(false);
            }
            if ((num1 <= 0 || num > 0) && (num1 <= 0 || num1 >= num))
            {
                return(false);
            }
            if (!flag)
            {
                return(flag1);
            }
            return(true);
        }
コード例 #7
0
        public static string ParseForKeywords(object o, string valstr, bool literal, out Type ptype)
        {
            ptype = null;
            if (valstr == null || valstr.Length <= 0)
            {
                return(null);
            }
            string str = valstr.Trim();

            string[] strArrays     = PropertyTest.ParseString(str, 2, "[");
            string[] matchingParen = null;
            string   str1          = null;

            if ((int)strArrays.Length > 1)
            {
                matchingParen = PropertyTest.ParseToMatchingParen(strArrays[1], '[', ']');
                str1          = matchingParen[0];
            }
            string[] strArrays1 = strArrays[0].Trim().Split(new char[] { ',' });
            if (str1 != null && str1.Length > 0 && strArrays1 != null && (int)strArrays1.Length > 0)
            {
                strArrays1[(int)strArrays1.Length - 1] = str1;
            }
            string str2 = strArrays1[0].Trim();
            char   chr  = str[0];

            if (chr == '.' || chr == '-' || chr == '+' || chr >= '0' && chr <= '9')
            {
                if (str.IndexOf(".") < 0)
                {
                    ptype = typeof(int);
                }
                else
                {
                    ptype = typeof(double);
                }
                return(str);
            }
            if (chr == '\"' || chr == '(')
            {
                ptype = typeof(string);
                return(str);
            }
            if (chr == '#')
            {
                ptype = typeof(string);
                return(str.Substring(1));
            }
            if (str.ToLower() == "true" || str.ToLower() == "false")
            {
                ptype = typeof(bool);
                return(str);
            }
            if (literal)
            {
                ptype = typeof(string);
                return(str);
            }
            string propertyValue = PropertyTest.GetPropertyValue(o, str2, out ptype);

            return(PropertyTest.ParseGetValue(propertyValue, ptype));
        }
コード例 #8
0
        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);
        }
コード例 #9
0
        public static string GetPropertyValue(object o, string name, out Type ptype)
        {
            string propertyValue;

            PropertyInfo[] propertyInfoArray;
            int            num;

            ptype = null;
            if (o == null || name == null)
            {
                return(null);
            }
            Type   type  = o.GetType();
            object value = null;

            PropertyInfo[] properties = type.GetProperties(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public);
            string[]       strArrays  = PropertyTest.ParseString(name, 2, ".");
            string         str        = strArrays[0];

            PropertyTest.ParseString(str, 4, ",");
            string str1 = strArrays[0];

            char[]   chrArray   = new char[] { '[' };
            string[] strArrays1 = str1.Split(chrArray);
            int      num1       = 0;

            if ((int)strArrays1.Length > 1)
            {
                str = strArrays1[0];
                string str2 = strArrays1[1];
                chrArray = new char[] { ']' };
                string[] strArrays2 = str2.Split(chrArray);
                if ((int)strArrays2.Length > 0)
                {
                    try
                    {
                        num1 = int.Parse(strArrays2[0]);
                    }
                    catch
                    {
                    }
                }
            }
            if ((int)strArrays.Length != 2)
            {
                PropertyInfo propertyInfo = PropertyTest.LookupPropertyInfo(type, str);
                if (propertyInfo != null)
                {
                    if (!propertyInfo.CanRead)
                    {
                        return("Property is write only.");
                    }
                    ptype = propertyInfo.PropertyType;
                    return(PropertyTest.InternalGetValue(o, propertyInfo, num1));
                }
                propertyInfoArray = properties;
                num = 0;
                while (num < (int)propertyInfoArray.Length)
                {
                    PropertyInfo propertyInfo1 = propertyInfoArray[num];
                    if (!PropertyTest.Insensitive.Equals(propertyInfo1.Name, str))
                    {
                        num++;
                    }
                    else if (propertyInfo1.CanRead)
                    {
                        ptype         = propertyInfo1.PropertyType;
                        propertyValue = PropertyTest.InternalGetValue(o, propertyInfo1, num1);
                        return(propertyValue);
                    }
                    else
                    {
                        propertyValue = "Property is write only.";
                        return(propertyValue);
                    }
                }
                return("Property not found.");
            }
            else
            {
                PropertyInfo propertyInfo2 = PropertyTest.LookupPropertyInfo(type, str);
                if (propertyInfo2 != null)
                {
                    if (!propertyInfo2.CanWrite)
                    {
                        return("Property is read only.");
                    }
                    ptype = propertyInfo2.PropertyType;
                    if (!ptype.IsArray)
                    {
                        value = propertyInfo2.GetValue(o, null);
                    }
                    else
                    {
                        try
                        {
                            object value1     = propertyInfo2.GetValue(o, null);
                            int    lowerBound = ((Array)value1).GetLowerBound(0);
                            int    upperBound = ((Array)value1).GetUpperBound(0);
                            if (num1 <= lowerBound && num1 <= upperBound)
                            {
                                value = ((Array)value1).GetValue(num1);
                            }
                        }
                        catch
                        {
                        }
                    }
                    return(PropertyTest.GetPropertyValue(value, strArrays[1], out ptype));
                }
                propertyInfoArray = properties;
                num = 0;
                while (num < (int)propertyInfoArray.Length)
                {
                    PropertyInfo propertyInfo3 = propertyInfoArray[num];
                    if (!PropertyTest.Insensitive.Equals(propertyInfo3.Name, str))
                    {
                        num++;
                    }
                    else if (propertyInfo3.CanWrite)
                    {
                        ptype = propertyInfo3.PropertyType;
                        if (!ptype.IsArray)
                        {
                            value = propertyInfo3.GetValue(o, null);
                        }
                        else
                        {
                            try
                            {
                                object value2      = propertyInfo3.GetValue(o, null);
                                int    lowerBound1 = ((Array)value2).GetLowerBound(0);
                                int    upperBound1 = ((Array)value2).GetUpperBound(0);
                                if (num1 <= lowerBound1 && num1 <= upperBound1)
                                {
                                    value = ((Array)value2).GetValue(num1);
                                }
                            }
                            catch
                            {
                            }
                        }
                        propertyValue = PropertyTest.GetPropertyValue(value, strArrays[1], out ptype);
                        return(propertyValue);
                    }
                    else
                    {
                        propertyValue = "Property is read only.";
                        return(propertyValue);
                    }
                }
                return("Property not found.");
            }
            return(propertyValue);
        }
コード例 #10
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);
        }
コード例 #11
0
        public static string GetPropertyValue(object o, string name, out Type ptype)
        {
            ptype = (Type)null;
            if (o == null || name == null)
            {
                return((string)null);
            }
            Type   type = o.GetType();
            object o1   = (object)null;

            PropertyInfo[] properties = type.GetProperties(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public);
            string[]       strArray1  = PropertyTest.ParseString(name, 2, ".");
            string         str        = strArray1[0];

            PropertyTest.ParseString(str, 4, ",");
            string[] strArray2 = strArray1[0].Split('[');
            int      index     = 0;

            if (strArray2.Length > 1)
            {
                str = strArray2[0];
                string[] strArray3 = strArray2[1].Split(']');
                if (strArray3.Length > 0)
                {
                    try
                    {
                        index = int.Parse(strArray3[0]);
                    }
                    catch
                    {
                    }
                }
            }
            if (strArray1.Length == 2)
            {
                PropertyInfo propertyInfo1 = PropertyTest.LookupPropertyInfo(type, str);
                if (propertyInfo1 != null)
                {
                    if (!propertyInfo1.CanWrite)
                    {
                        return("Property is read only.");
                    }
                    ptype = propertyInfo1.PropertyType;
                    if (ptype.IsArray)
                    {
                        try
                        {
                            object obj        = propertyInfo1.GetValue(o, (object[])null);
                            int    lowerBound = ((Array)obj).GetLowerBound(0);
                            int    upperBound = ((Array)obj).GetUpperBound(0);
                            if (index <= lowerBound)
                            {
                                if (index <= upperBound)
                                {
                                    o1 = ((Array)obj).GetValue(index);
                                }
                            }
                        }
                        catch
                        {
                        }
                    }
                    else
                    {
                        o1 = propertyInfo1.GetValue(o, (object[])null);
                    }
                    return(PropertyTest.GetPropertyValue(o1, strArray1[1], out ptype));
                }
                foreach (PropertyInfo propertyInfo2 in properties)
                {
                    if (PropertyTest.Insensitive.Equals(propertyInfo2.Name, str))
                    {
                        if (!propertyInfo2.CanWrite)
                        {
                            return("Property is read only.");
                        }
                        ptype = propertyInfo2.PropertyType;
                        if (ptype.IsArray)
                        {
                            try
                            {
                                object obj        = propertyInfo2.GetValue(o, (object[])null);
                                int    lowerBound = ((Array)obj).GetLowerBound(0);
                                int    upperBound = ((Array)obj).GetUpperBound(0);
                                if (index <= lowerBound)
                                {
                                    if (index <= upperBound)
                                    {
                                        o1 = ((Array)obj).GetValue(index);
                                    }
                                }
                            }
                            catch
                            {
                            }
                        }
                        else
                        {
                            o1 = propertyInfo2.GetValue(o, (object[])null);
                        }
                        return(PropertyTest.GetPropertyValue(o1, strArray1[1], out ptype));
                    }
                }
            }
            else
            {
                PropertyInfo p1 = PropertyTest.LookupPropertyInfo(type, str);
                if (p1 != null)
                {
                    if (!p1.CanRead)
                    {
                        return("Property is write only.");
                    }
                    ptype = p1.PropertyType;
                    return(PropertyTest.InternalGetValue(o, p1, index));
                }
                foreach (PropertyInfo p2 in properties)
                {
                    if (PropertyTest.Insensitive.Equals(p2.Name, str))
                    {
                        if (!p2.CanRead)
                        {
                            return("Property is write only.");
                        }
                        ptype = p2.PropertyType;
                        return(PropertyTest.InternalGetValue(o, p2, index));
                    }
                }
            }
            return("Property not found.");
        }