예제 #1
0
        private object DeserializeValue(Type type, JsonNode value)
        {
            if (type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }

            if (value.Type == JsonType.Null)
            {
                return(null);
            }

            var typeDetails = TypeDetails.Get(type);

            if (typeDetails.JsonConverter != null)
            {
                return(typeDetails.JsonConverter.FromJson(value));
            }
            else if (typeDetails.IsEnum)
            {
                return(Enum.Parse(type, value.ToString(), ignoreCase: true));
            }
            else if (type.IsArray)
            {
                return(DeserializeArray(type, (JsonArray)value));
            }
            else if (typeDetails.IsList)
            {
                return(DeserializeList(type, (JsonArray)value));
            }
            else
            {
                var contract = JsonModelCache.Get(type);

                return(DeserializeObject(contract, (JsonObject)value));
            }
        }