Пример #1
0
        static void Main(string[] args)
        {
            var myObject = new MyObject(
                100,
                SingleCaseUnion.NewSingleCaseUnion(12345),
                DiscriminatedUnion.NewCase1DU(111, "aaa"),
                ListModule.OfSeq(new[] { 0, 1, 2, 3, 4, 5 }),
                MapModule.OfSeq(new[] { Tuple.Create("One", 1), Tuple.Create("Two", 2) }),
                Tuple.Create("Hello", "F# fans"),
                FSharpOption <string> .Some("Option1")
                );

            //var converters = new JsonConverter[0];
            var converters = new JsonConverter[] { new UnionConverter() };

            // Test a single serialize and deserialize
            var json        = JsonConvert.SerializeObject(myObject, converters);
            var myNewObject = JsonConvert.DeserializeObject <MyObject>(json, converters);

            Console.WriteLine("Writing {0}", json);
            //Console.WriteLine("Objects are the same {0}", (myObject == myNewObject));

            var count = 10000;

            Duration(() => SerializeLoad(false, count, myObject, converters), count, "Serialize Default");
            Duration(() => DeserializeLoad(false, count, myObject, converters), count, "Deserialize Default");
            Duration(() => SerializeLoad(true, count, myObject, converters), count, "Serialize Custom");
            Duration(() => DeserializeLoad(true, count, myObject, converters), count, "Deserialize Custom");
        }