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 int Add(MemberMapping memberMapping) { if (this.Contains(memberMapping.MappingName)) { if (memberMapping.Ignored) { return(-1); } MemberMapping mapping = this[memberMapping.MappingName]; if (!mapping.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)); } this.Remove(mapping); } this._dict[memberMapping.MappingName] = memberMapping; return(base.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) ; }
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; }
public void Remove(MemberMapping value) { this._dict.Remove(value.MappingName); base.List.Remove(value); }
public int IndexOf(MemberMapping value) { return(base.List.IndexOf(value)); }
public bool Contains(MemberMapping value) { return(base.List.Contains(value)); }
public void Remove(MemberMapping value) { _dict.Remove(value.MappingName); List.Remove(value); }