Ejemplo n.º 1
0
        public static object ObjectStringToType(string strType)
        {
            var type = ExtractType(strType);

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

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

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

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

            return(Serializer.UnescapeString(strType));
        }
Ejemplo n.º 2
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));
                }
            }

            return((JsConfig.TryToParsePrimitiveTypeValues
                ? ParsePrimitive(strType.Value)
                : null) ?? Serializer.UnescapeString(strType).Value);
        }
Ejemplo n.º 3
0
        public static object ObjectStringToType(ReadOnlySpan <char> strType)
        {
            var type = ExtractType(strType);

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

            var config = JsConfig.GetConfig();

            if (config.ConvertObjectTypesIntoStringDictionary && !strType.IsNullOrEmpty())
            {
                var firstChar = strType[0];
                var endChar   = strType[strType.Length - 1];
                if (firstChar == JsWriter.MapStartChar && endChar == JsWriter.MapEndChar)
                {
                    var dynamicMatch = DeserializeDictionary <TSerializer> .ParseDictionary <string, object>(strType, null, v => Serializer.UnescapeString(v).ToString(), v => Serializer.UnescapeString(v).ToString());

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

                if (firstChar == JsWriter.ListStartChar && endChar == JsWriter.ListEndChar)
                {
                    return(DeserializeList <List <object>, TSerializer> .ParseStringSpan(strType));
                }
            }

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

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

            if (Serializer.ObjectDeserializer != null && typeof(TSerializer) == typeof(Json.JsonTypeSerializer))
            {
                return(!strType.IsNullOrEmpty()
                    ? Serializer.ObjectDeserializer(strType)
                    : strType.Value());
            }

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