示例#1
0
        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);
        }
示例#2
0
        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);
        }
示例#3
0
        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();
        }
示例#4
0
        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);
        }
示例#5
0
 public Boolean Contains(JsonPropertyName propertyName) => m_dictionary.ContainsKey(propertyName);
示例#6
0
        public void UsesJsonNetPropertyNames()
        {
            var thing = new JsonPropertyName();

            Assert.That(thing.ToQueryString(), Is.EqualTo("a=&b=0"));
        }