public override TCollection Read(JsonReader reader, Type objectType)
        {
            var builder = new CollectionBuilder <TCollection, TItem>();

            reader.ReadStartArray();

            if (PrimitiveFormatter <TItem> .CanRead)
            {
                while (reader.Peek() != JsonToken.EndArray)
                {
                    builder.Add(reader.ReadValue <TItem>());
                }
            }
            else
            {
                var contract = reader.Settings.ResolveContract(typeof(TItem));

                while (reader.Peek() != JsonToken.EndArray)
                {
                    builder.Add(reader.ReadValueInternal <TItem>(contract));
                }
            }

            reader.ReadEndArray();

            return(builder.ToCollection());
        }
Beispiel #2
0
        public FormUrlEncodedContent AsFormUrlEncodedContent()
        {
            if (!string.IsNullOrEmpty(Id))
            {
                return(new CollectionBuilder().Add("batch[id]".ToKvp(Id)).AsFormUrlEncodedContent());
            }

            var collection = new CollectionBuilder();

            if (Shipments != null)
            {
                for (var i = 0; i < Shipments.Count; i++)
                {
                    var keyBase = string.Format("batch[shipment][{0}]", i);
                    collection.AddShipment(keyBase, Shipments[i]);
                    collection.Add("[carrier]".ToKvp(keyBase, Shipments[i].Carrier));
                    collection.Add("[service]".ToKvp(keyBase, Shipments[i].Service));
                }
            }

            return(collection.AsFormUrlEncodedContent());
        }
Beispiel #3
0
        public override TCollection Read(JsonReader reader, Type objectType)
        {
            var builder = new CollectionBuilder <TCollection, Object>();

            reader.ReadStartArray();

            while (reader.Peek() != JsonToken.EndArray)
            {
                builder.Add(reader.ReadValue <Object>());
            }

            reader.ReadEndArray();

            return(builder.ToCollection());
        }
Beispiel #4
0
        public override TDictionary Read(JsonReader reader, Type objectType)
        {
            var builder = new CollectionBuilder <TDictionary, KeyValuePair <String, TValue> >();

            reader.ReadStartObject();

            while (reader.Peek() == JsonToken.PropertyName)
            {
                var propertyName = reader.ReadPropertyName();
                var value        = reader.ReadValue <TValue>();

                builder.Add(new KeyValuePair <String, TValue>(propertyName, value));
            }

            reader.ReadEndObject();

            return(builder.ToCollection());
        }