Ejemplo n.º 1
0
        static void OverrideGetters(JsonMemberGetter getter, MemberOverride mo)
        {
            if (mo.Serializable.HasValue)
            {
                getter.Serializable = Constants.ToTriState(mo.Serializable);
            }
            if (mo._NonSerializedValues != null)
            {
                getter.NonSerializedValues = new object[mo.NonSerializedValues.Count];
                mo.NonSerializedValues.CopyTo(getter.NonSerializedValues, 0);
                getter.HasNonSerializedValue = getter.NonSerializedValues.Length > 0;
            }
            if (mo.OverrideTypedNames)
            {
                getter.TypedNames = mo.TypedNames;
            }
            if (mo.OverrideSerializedName || mo.OverrideTypedNames)
            {
                if (mo.SerializedName == getter.MemberName)
                {
                    getter.SpecificName = getter.TypedNames != null && getter.TypedNames.Count > 0;
                }
                else
                {
                    getter.SpecificName = true;
                }
            }

            if (mo.OverrideConverter)
            {
                getter.Converter = mo.Converter;
            }
            if (mo.OverrideItemConverter)
            {
                getter.ItemConverter = mo.ItemConverter;
            }
        }
Ejemplo n.º 2
0
 private static void OverrideJsonPropertyInfo(Dictionary <string, JsonMemberSetter> s, MemberOverride mo, JsonMemberSetter mp)
 {
     foreach (var item in s)
     {
         mp = item.Value;
         if (mp.MemberName == mo.MemberName)
         {
             if (mo.OverrideConverter)
             {
                 mp.Converter = mo.Converter;
             }
             if (mo.OverrideItemConverter)
             {
                 mp.ItemConverter = mo.ItemConverter;
             }
             if (mo.Deserializable.HasValue)
             {
                 mp.CanWrite = mo.Deserializable == true;
             }
         }
     }
 }
Ejemplo n.º 3
0
        void OverridePropInfo(Type type, Dictionary <string, JsonMemberSetter> s, MemberOverride mo, JsonMemberGetter g)
        {
            JsonMemberSetter mp = null;

            if (mo.OverrideTypedNames)
            {
                // remove previous polymorphic deserialization info
                var rt = new List <string> ();
                foreach (var item in s)
                {
                    if (item.Value.MemberName == mo.MemberName)
                    {
                        if (Equals(item.Value.Member.MemberType, g.Member.MemberType) == false)
                        {
                            rt.Add(item.Key);
                        }
                        // find an item with the same member name
                        mp = item.Value;
                    }
                }
                if (mp == null)
                {
                    throw new MissingMemberException(g.Member.MemberType.FullName, mo.MemberName);
                }
                foreach (var item in rt)
                {
                    s.Remove(item);
                }
                // add new polymorphic deserialization info
                if (mo.TypedNames.Count > 0)
                {
                    foreach (var item in mo.TypedNames)
                    {
                        var t = item.Key;
                        if (g.Member.MemberType.IsAssignableFrom(t) == false)
                        {
                            throw new InvalidCastException("The type (" + t.FullName + ") does not derive from the member type (" + g.Member.MemberType.FullName + ")");
                        }
                        var n = item.Value;
                        var p = new JsonMemberSetter(new MemberCache(t, g.MemberName, mp.Member)
                        {
                            MemberTypeReflection = GetReflectionCache(t)
                        });
                        JsonMemberSetter tp;
                        if (s.TryGetValue(n, out tp) && Equals(tp.Member.MemberType, g.Member.MemberType))
                        {
                            s[n] = p;
                        }
                        else
                        {
                            s.Add(n, p);
                        }
                    }
                }
            }
            else if (mo.OverrideSerializedName && g.SerializedName != mo.SerializedName)
            {
                if (s.TryGetValue(g.SerializedName, out mp))
                {
                    s.Remove(g.SerializedName);
                    s.Add(mo.SerializedName, mp);
                }
            }
            OverrideJsonPropertyInfo(s, mo, mp);
            if (mo.OverrideSerializedName)
            {
                g.SerializedName = mo.SerializedName;
            }
        }