예제 #1
0
		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);
		}
예제 #2
0
 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));
 }
예제 #3
0
		public bool Contains( MemberMapping value )  
		{
			return List.Contains(value);
		}
예제 #4
0
		public void Remove( MemberMapping value )  
		{
			_dict.Remove(value.MappingName);
			List.Remove(value);
		}
예제 #5
0
		public int IndexOf( MemberMapping value )  
		{
			return List.IndexOf(value) ;
		}
예제 #6
0
		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;
		}
예제 #7
0
 public void Remove(MemberMapping value)
 {
     this._dict.Remove(value.MappingName);
     base.List.Remove(value);
 }
예제 #8
0
 public int IndexOf(MemberMapping value)
 {
     return(base.List.IndexOf(value));
 }
예제 #9
0
 public bool Contains(MemberMapping value)
 {
     return(base.List.Contains(value));
 }
 public void Remove(MemberMapping value)
 {
     _dict.Remove(value.MappingName);
     List.Remove(value);
 }