示例#1
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);
        }
示例#2
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));
        }