public int Add( MemberMapping memberMapping ) { if (Contains(memberMapping.MappingName)) { // don't overwrite existing mapping with ignored mapping if (memberMapping.Ignored) return -1; MemberMapping existingMemberMapping = this[memberMapping.MappingName]; if (!existingMemberMapping.Ignored) { throw new JsonSerializationException( string.Format( "A member with the name '{0}' already exists on {1}. Use the JsonPropertyAttribute to specify another name.", memberMapping.MappingName, memberMapping.Member.DeclaringType)); } else { // remove ignored mapping so it can be replaced in collection Remove(existingMemberMapping); } } _dict[memberMapping.MappingName] = memberMapping; return List.Add(memberMapping); }
public bool Contains(MemberMapping value) { return(List.Contains(value)); }
public void Remove(MemberMapping value) { _dict.Remove(value.MappingName); List.Remove(value); }
public int IndexOf(MemberMapping value) { return(List.IndexOf(value)); }
public bool Contains( MemberMapping value ) { return List.Contains(value); }
public void Remove( MemberMapping value ) { _dict.Remove(value.MappingName); List.Remove(value); }
public int IndexOf( MemberMapping value ) { return List.IndexOf(value) ; }
private MemberMappingCollection CreateMemberMappings(Type objectType) { MemberInfo[] members = ReflectionUtils.GetFieldsAndProperties(objectType, BindingFlags.Public | BindingFlags.Instance); MemberMappingCollection memberMappings = new MemberMappingCollection(); foreach (MemberInfo member in members) { string mappedName; JsonPropertyAttribute propertyAttribute = ReflectionUtils.GetAttribute(typeof(JsonPropertyAttribute), member, true) as JsonPropertyAttribute; if (propertyAttribute != null) mappedName = propertyAttribute.PropertyName; else mappedName = member.Name; bool ignored = member.IsDefined(typeof (JsonIgnoreAttribute), true); bool readable = ReflectionUtils.CanReadMemberValue(member); bool writable = ReflectionUtils.CanSetMemberValue(member); MemberMapping memberMapping = new MemberMapping(mappedName, member, ignored, readable, writable); memberMappings.Add(memberMapping); } return memberMappings; }