예제 #1
0
        public static void testMap()
        {
            var t2 = new SubKuaidiListItem {
                KuaidiName = "Hey", KuaidiNumber = "long"
            };
            var myType = t2.GetType();

            object myObj = System.Activator.CreateInstance(myType);



            var    mapProperty = new Dictionary <string, string>();
            Object obj;

            (obj, mapProperty) = ObjectToMapWithDict(myObj);

            Console.WriteLine("=myObj=");
            Console.WriteLine(JsonConvert.SerializeObject(ObjectToMap(myObj)));

            Console.WriteLine("=obj=");

            Console.WriteLine(JsonConvert.SerializeObject(obj));

            Console.WriteLine("=mapProperty=");
            Console.WriteLine(JsonConvert.SerializeObject(mapProperty));
        }
예제 #2
0
        public static Dictionary <string, string> MapFormJsonProperty2()
        {
            var t = new SubKuaidiListItem {
            };

            var t2 = new SubKuaidiListItem {
                KuaidiName = "Hey", KuaidiNumber = "long"
            };
            var dict = new Dictionary <string, string>();

            var    mapProperty = new Dictionary <string, string>();
            Object obj;

            (obj, dict) = ObjectToMapWithDict(t);

            Console.WriteLine(JsonConvert.SerializeObject(dict));
            var serializedObj = JsonConvert.SerializeObject(obj);
            var map           = ObjectToMap(t2);
            Dictionary <string, string> dictJsonProperty = JsonConvert.DeserializeObject <Dictionary <string, string> >(
                JsonConvert.SerializeObject(t));
            var dictProperty = new Dictionary <string, string>();

            foreach (var item in dictJsonProperty)
            {
                var realPropertyName = dict[item.Value];
                dictProperty.Add(item.Key, dict[item.Value]);
                map.GetValueOrDefault(realPropertyName);
                mapProperty.Add(item.Key, map.GetValueOrDefault(realPropertyName));
            }
            Console.WriteLine(JsonConvert.SerializeObject(dictProperty));

            Console.WriteLine(JsonConvert.SerializeObject(mapProperty));

            return(mapProperty);
        }
예제 #3
0
        public static void test()
        {
            var t2 = new SubKuaidiListItem {
                KuaidiName = "Hey", KuaidiNumber = "long"
            };
            var list = new List <SubKuaidiListItem>();

            list.Add(t2);
            list.Add(t2);
            MapFormJsonProperty(t2);
            var co = new DeliveryinfoRequest()
            {
                ShopId = "2321", SubKuaidiList = list
            };


            var c = CompoundObjectToMap(co);

            Console.WriteLine(JsonConvert.SerializeObject(c));
            #region MyRegion

            //var myType = t2.GetType();

            //object myObj = System.Activator.CreateInstance(myType);



            //var mapProperty = new Dictionary<string, string>();
            //Object obj;
            //(obj, mapProperty) = ObjectToMapWithDict(myObj);

            //Console.WriteLine("=myObj=");
            //Console.WriteLine(JsonConvert.SerializeObject(ObjectToMap(myObj)));

            //Console.WriteLine("=obj=");

            //Console.WriteLine(JsonConvert.SerializeObject(obj));

            //Console.WriteLine("=mapProperty=");
            //Console.WriteLine(JsonConvert.SerializeObject(mapProperty));

            #endregion
        }