Beispiel #1
0
        private static object FromStringVector(Type type, string src)
        {
            Type type2 = typeof(List).MakeGenericType(new Type[]
            {
                type
            });
            IList list = (IList)Activator.CreateInstance(type2);

            if (string.IsNullOrEmpty(src))
            {
                return(list);
            }
            int    num  = src.IndexOf(':');
            string text = src.Substring(0, num);
            int    num2 = int.Parse(text);
            int    num3 = num + 1;
            int    num4 = num3;

            if (num3 < src.get_Length() && src.get_Chars(num3) == '{')
            {
                num4 = StringUtils.SkipPairedBrackets(src, num3);
            }
            for (num4 = src.IndexOf('|', num4); num4 != -1; num4 = src.IndexOf('|', num4))
            {
                int    num5   = num4 - num3;
                string valStr = src.Substring(num3, num5);
                object obj    = StringUtils.FromString(type, valStr, false);
                list.Add(obj);
                num3 = num4 + 1;
                if (num3 < src.get_Length() && src.get_Chars(num3) == '{')
                {
                    num4 = StringUtils.SkipPairedBrackets(src, num3);
                }
                else
                {
                    num4 = num3;
                }
            }
            if (num3 < src.get_Length())
            {
                int    num6    = src.get_Length() - num3;
                string valStr2 = src.Substring(num3, num6);
                object obj2    = StringUtils.FromString(type, valStr2, false);
                list.Add(obj2);
            }
            return(list);
        }
Beispiel #2
0
        private static object FromStringStruct(Type type, string src)
        {
            object obj = Activator.CreateInstance(type);
            DictionaryView <string, FieldInfo> dictionaryView = new DictionaryView <string, FieldInfo>();

            FieldInfo[] fields = type.GetFields(62);
            for (int i = 0; i < fields.Length; i++)
            {
                FieldInfo fieldInfo = fields[i];
                if (!fieldInfo.get_IsLiteral())
                {
                    dictionaryView.Add(fieldInfo.get_Name(), fieldInfo);
                }
            }
            if (string.IsNullOrEmpty(src))
            {
                return(obj);
            }
            int num  = StringUtils.SkipPairedBrackets(src, 0);
            int num2 = 1;
            int num3 = src.IndexOf(';', num2);

            while (num3 != -1)
            {
                if (num3 > num2)
                {
                    int    num4 = src.IndexOf('=', num2);
                    int    num5 = num4 - num2;
                    string key  = src.Substring(num2, num5);
                    char   c    = src.get_Chars(num4 + 1);
                    string valStr;
                    if (c != '{')
                    {
                        num5   = num3 - num4 - 1;
                        valStr = src.Substring(num4 + 1, num5);
                    }
                    else
                    {
                        int num6 = 0;
                        num6 += num4 + 1;
                        int num7 = StringUtils.SkipPairedBrackets(src, num6);
                        num5   = num7 - num6 + 1;
                        valStr = src.Substring(num4 + 1, num5);
                        num3   = num4 + 1 + num5;
                    }
                    if (dictionaryView.ContainsKey(key))
                    {
                        FieldInfo fieldInfo2 = dictionaryView[key];
                        object    obj2       = StringUtils.FromString(fieldInfo2.get_FieldType(), valStr, false);
                        fieldInfo2.SetValue(obj, obj2);
                    }
                }
                num2 = num3 + 1;
                num3 = src.IndexOf(';', num2);
                if (num3 > num)
                {
                    break;
                }
            }
            return(obj);
        }