Esempio n. 1
0
        private static Dictionary <SerializationInfo, object> _DeserializeValues <T>(T obj, JsonValue json, JsonSerializer serializer, IEnumerable <SerializationInfo> members, bool ignoreCase)
        {
            var dict = new Dictionary <SerializationInfo, object>();

            foreach (var memberInfo in members)
            {
                var name = memberInfo.SerializationName;
                if (memberInfo.ShouldTransform)
                {
                    name = serializer.Options.DeserializationNameTransform(name);
                }

                var visited = new HashSet <string>(ignoreCase ? StringComparer.OrdinalIgnoreCase : StringComparer.Ordinal);
                if (_TryGetKeyValue(json, name, ignoreCase, out var value) &&
                    visited.Add(name))
                {
                    Func <JsonSerializer, JsonValue, object> deserialize;
                    if (memberInfo.MemberInfo is PropertyInfo info)
                    {
                        deserialize = SerializerCache.GetDeserializeMethod(info.PropertyType);
                    }
                    else
                    {
                        deserialize = SerializerCache.GetDeserializeMethod(((FieldInfo)memberInfo.MemberInfo).FieldType);
                    }
                    var valueObj = deserialize(serializer, value);
                    if (value.Type == JsonValueType.Object && value.Object.ContainsKey(Constants.RefKey))
                    {
                        var guid = new Guid(value.Object[Constants.RefKey].String);
                        var pair = serializer.SerializationMap[guid];
                        if (pair.DeserializationIsComplete)
                        {
                            dict.Add(memberInfo, valueObj);
                        }
                        else
                        {
                            if (memberInfo.MemberInfo is PropertyInfo property)
                            {
                                pair.AddReference(property, obj);
                            }
                            else
                            {
                                pair.AddReference((FieldInfo)memberInfo.MemberInfo, obj);
                            }
                        }
                        value.Object.Remove(Constants.RefKey);
                    }
                    else
                    {
                        dict.Add(memberInfo, valueObj);
                    }
                }
            }
            return(dict);
        }