Exemplo n.º 1
0
        public override object Deserialize(IDictionary <string, object> dictionary, Type type, JavaScriptSerializer serializer)
        {
            VoucherItemCollection data = new VoucherItemCollection();

            data.CollectioName = dictionary.GetValue("collectioName", string.Empty);
            JSONSerializerExecute.FillDeserializedCollection(dictionary["items"], data);

            return(data);
        }
Exemplo n.º 2
0
        public override IDictionary <string, object> Serialize(object obj, JavaScriptSerializer serializer)
        {
            Dictionary <string, object> dictionary = new Dictionary <string, object>();

            VoucherItemCollection data = (VoucherItemCollection)obj;

            dictionary.AddNonDefaultValue("collectioName", data.CollectioName);
            dictionary["items"] = data.ToArray();

            return(dictionary);
        }
Exemplo n.º 3
0
        private static void AssertVoucherItemCollection(VoucherItemCollection source, VoucherItemCollection dest, bool withCollectionName = true)
        {
            Assert.AreEqual(source.Count, dest.Count);

            if (withCollectionName)
            {
                Assert.AreEqual(source.CollectioName, dest.CollectioName);
            }

            for (int i = 0; i < source.Count; i++)
            {
                AssertVoucherItem(source[i], dest[i]);
            }
        }
Exemplo n.º 4
0
        public void VoucherItemCollectionWithConverterJsonTest()
        {
            JSONSerializerExecute.RegisterConverter(typeof(VoucherConverter));
            JSONSerializerExecute.RegisterConverter(typeof(VoucherItemCollectionConverter));

            VoucherEntity source = VoucherEntity.PrepareData();

            string json = JSONSerializerExecute.SerializeWithType(source.Items, true);

            Console.WriteLine(json);

            JavaScriptSerializer serializer = JSONSerializerFactory.GetJavaScriptSerializer(typeof(VoucherItemCollection));

            VoucherItemCollection deserialized = JSONSerializerExecute.DeserializeString <VoucherItemCollection>(json);

            AssertVoucherItemCollection(source.Items, deserialized);
        }