protected private JsonProperty(JsonObjectContract <TOwner> parent, MemberInfo member) { if (member == null) { throw new ArgumentNullException(nameof(member)); } Parent = parent ?? throw new ArgumentNullException(nameof(parent)); DeclaringType = member.DeclaringType; UnderlyingName = member.Name; var propertyAttribute = ReflectionHelpers.GetAttribute <JsonPropertyAttribute>(member); var mappedName = member.Name; if (propertyAttribute != null) { Order = propertyAttribute.Order; Required = propertyAttribute.Required; SerializeNulls = propertyAttribute.ShouldSerializeNulls() ?? parent.Settings.SerializeNulls; if (propertyAttribute.Name != null) { mappedName = propertyAttribute.Name; } } else { SerializeNulls = parent.Settings.SerializeNulls; } Name = JsonPropertyName.GetOrCreate(mappedName); PropertyType = ReflectionHelpers.GetFieldOrPropertyType(member); NonNullablePropertyType = Nullable.GetUnderlyingType(PropertyType) ?? PropertyType; Converter = ReflectionHelpers.GetAttribute <JsonConverterAttribute>(member)?.CreateInstance(NonNullablePropertyType); }
public Boolean Remove(JsonPropertyName propertyName) { CheckNotFrozen(); if (m_dictionary.TryGetValue(propertyName, out var properties)) { var item = properties.First; while (item != null) { if (item.Value.Name == propertyName) { properties.Remove(item); m_list.Remove(item.Value); if (properties.Count == 0) { m_dictionary.Remove(propertyName); } return(true); } item = item.Next; } } return(false); }
public override void WriteValue(JsonWriter writer, Object value) { writer.WriteStartObject(); foreach (var item in (IEnumerable <KeyValuePair <String, Object> >)value) { writer.WritePropertyName(JsonPropertyName.GetOrCreate(item.Key)); writer.WriteValue(item.Value); } writer.WriteEndObject(); }
public JsonProperty <TOwner> FindProperty(JsonPropertyName propertyName, Boolean ignoreCase) { if (m_dictionary.TryGetValue(propertyName, out var properties)) { var item = properties.First; if (ignoreCase) { return(item.Value); } while (item != null) { if (item.Value.Name.Value == propertyName.Value) { return(item.Value); } item = item.Next; } } return(null); }
public Boolean Contains(JsonPropertyName propertyName) => m_dictionary.ContainsKey(propertyName);
public void UsesJsonNetPropertyNames() { var thing = new JsonPropertyName(); Assert.That(thing.ToQueryString(), Is.EqualTo("a=&b=0")); }