Пример #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);
 }