Esempio n. 1
0
        public static object ObjectStringToType(StringSegment strType)
        {
            var type = ExtractType(strType);

            if (type != null)
            {
                var parseFn       = Serializer.GetParseStringSegmentFn(type);
                var propertyValue = parseFn(strType);
                return(propertyValue);
            }

            if (JsConfig.ConvertObjectTypesIntoStringDictionary && !strType.IsNullOrEmpty())
            {
                if (strType.GetChar(0) == JsWriter.MapStartChar)
                {
                    var dynamicMatch = DeserializeDictionary <TSerializer> .ParseDictionary <string, object>(strType, null, v => Serializer.UnescapeString(v).Value, v => Serializer.UnescapeString(v).Value);

                    if (dynamicMatch != null && dynamicMatch.Count > 0)
                    {
                        return(dynamicMatch);
                    }
                }

                if (strType.GetChar(0) == JsWriter.ListStartChar)
                {
                    return(DeserializeList <List <object>, TSerializer> .ParseStringSegment(strType));
                }
            }

            var primitiveType = JsConfig.TryToParsePrimitiveTypeValues ? ParsePrimitive(strType.Value) : null;

            if (primitiveType != null)
            {
                return(primitiveType);
            }

            if (Serializer.ObjectDeserializer != null)
            {
                return(Serializer.ObjectDeserializer(strType));
            }

            return(Serializer.UnescapeString(strType).Value);
        }