예제 #1
0
        public void SetValue(string vName, object vValue)
        {
            if (vValue == null)
            {
                return;
            }
            cacheObje = vValue;

            this.name = vName;
            Type type = vValue.GetType();

            typeName = type.FullName;

            if (type.IsPrimitive || type == typeof(string))
            {
                value     = vValue.ToString();
                valueType = ValueType.CsharpBaseValue;
            }
            else if (type.IsArray)
            {
                typeName  = type.GetElementType().FullName;
                value     = JsonUtils.ArrayToJson(vValue);
                valueType = ValueType.Array;
            }
            else if (type.IsGenericType)
            {
                if (typeof(List <>).Name == type.Name)
                {
                    Type t = type.GetGenericArguments()[0];
                    typeName  = t.FullName;
                    value     = JsonUtils.ListToJson(vValue);
                    valueType = ValueType.List;
                }
                else if (typeof(Dictionary <,>).Name == type.Name)
                {
                    Type[] tArr = type.GetGenericArguments();
                    typeName  = tArr[0].FullName + "," + tArr[1].FullName;
                    valueType = ValueType.Dictionary;
                    value     = JsonUtils.DictionaryToJson(vValue);
                }
            }
            else if (type.IsEnum)
            {
                value     = ((int)vValue).ToString();
                valueType = ValueType.Enum;
            }
            else
            {
                if (type.IsClass || type.IsValueType)
                {
                    valueType = ValueType.ClassOrStruct;
                    value     = JsonUtils.ClassOrStructToJson(vValue);
                }
            }
        }