Esempio n. 1
0
        public static object FromString(Type type, string valStr, bool bStrIsArrayType /*= false*/)
        {
            if (!string.IsNullOrEmpty(valStr) && valStr == "null")
            {
                Debug.Check(Utils.IsRefNullType(type));
                return(null);
            }

            if (type.IsByRef)
            {
                type = type.GetElementType();
            }

            bool bIsArrayType = Utils.IsArrayType(type);

            object v = null;

            //customized type, struct or enum
            if (bStrIsArrayType || bIsArrayType)
            {
                if (bIsArrayType)
                {
                    Type elemType = type.GetGenericArguments()[0];
                    v = StringUtils.FromStringVector(elemType, valStr);
                }
                else
                {
                    v = StringUtils.FromStringVector(type, valStr);
                }
            }
            else if (type == typeof(behaviac.IProperty))
            {
                v = AgentMeta.ParseProperty(valStr);
            }
            else if (Utils.IsCustomClassType(type))
            {
                v = StringUtils.FromStringStruct(type, valStr);
            }
            else
            {
                v = Utils.FromStringPrimitive(type, valStr);
            }

            return(v);
        }
Esempio n. 2
0
        public static object FromString(Type type, string valStr, bool bStrIsArrayType)
        {
            if (!string.IsNullOrEmpty(valStr) && valStr == "null")
            {
                return(null);
            }
            if (type.get_IsByRef())
            {
                type = type.GetElementType();
            }
            bool   flag = Utils.IsArrayType(type);
            object result;

            if (bStrIsArrayType || flag)
            {
                if (flag)
                {
                    Type type2 = type.GetGenericArguments()[0];
                    result = StringUtils.FromStringVector(type2, valStr);
                }
                else
                {
                    result = StringUtils.FromStringVector(type, valStr);
                }
            }
            else if (type == typeof(Property))
            {
                result = Condition.LoadProperty(valStr);
            }
            else if (Utils.IsCustomClassType(type))
            {
                result = StringUtils.FromStringStruct(type, valStr);
            }
            else
            {
                result = Utils.GetValueFromString(type, valStr);
            }
            return(result);
        }