JsonMemberGetter[] GetGetters(SerializationInfo typeInfo, MemberCache[] members, IReflectionController controller) { var r = new List <JsonMemberGetter> (members.Length); foreach (var m in members) { var g = new JsonMemberGetter(typeInfo, m, this); var mi = m.MemberInfo; g.Serializable = Constants.ToTriState(controller.IsMemberSerializable(mi, m)); if (g.Member.HasPublicGetter == false && CanSerializePrivateMembers == false) { continue; } g.Converter = controller.GetMemberConverter(mi); g.ItemConverter = controller.GetMemberItemConverter(mi); var dv = controller.GetNonSerializedValues(mi); if (dv != null) { var v = new List <object> (); foreach (var item in dv) { v.Add(item); } g.NonSerializedValues = v.ToArray(); } g.HasNonSerializedValue = g.NonSerializedValues != null; var tn = controller.GetSerializedNames(mi); if (tn != null) { if (String.IsNullOrEmpty(tn.DefaultName) == false && tn.DefaultName != g.SerializedName) { g.SpecificName = true; } g.SerializedName = tn.DefaultName ?? g.SerializedName; if (tn.Count > 0) { g.TypedNames = new Dictionary <Type, string> (tn); g.SpecificName = true; } } r.Add(g); } return(r.ToArray()); }
static void OverrideGetter(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; } }
void OverrideSetter(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(g.OwnerTypeInfo, new MemberCache(t, g.MemberName, mp.Member), this); 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); } } OverrideJsonSetter(s, mo); if (mo.OverrideSerializedName) { g.SerializedName = mo.SerializedName; } }