Exemplo n.º 1
0
        static void Main(string[] args)
        {
            var novelist = new Novelist
            {
                Name = "test", Birth = new DateTime(2021, 4, 24), Masterpieces = new[] { "test" }
            };

            Exercise2_2(novelist, "novelist.json");
            Console.WriteLine(File.ReadAllText("novelist.json"));
            Console.WriteLine();
        }
Exemplo n.º 2
0
 static void Exercise2_2(Novelist novelist, string outfile)
 {
     using (var stream = new FileStream(outfile, FileMode.Create,
                                        FileAccess.Write))
     {
         var serializer = new DataContractJsonSerializer(novelist.GetType(),
                                                         new DataContractJsonSerializerSettings
         {
             DateTimeFormat = new DateTimeFormat("yyyy-MM-dd'T'HH:mm:ssZ")
         });
         serializer.WriteObject(stream, novelist);
     }
 }