예제 #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"));
        }