Last active
November 14, 2018 09:22
-
-
Save keithn/bb03b6de07e8deada05e5eb87fcc30ed to your computer and use it in GitHub Desktop.
Simple Diary to Json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.IO; | |
using DemoDiary; | |
using Newtonsoft.Json; | |
namespace DemoDiary | |
{ | |
public class Diary | |
{ | |
public List<Entry> Entries { get; set; } = new List<Entry>(); | |
public void Add(string v) | |
{ | |
Entries.Add(new Entry(){Text = v, Time = DateTimeOffset.Now}); | |
} | |
} | |
public class Entry | |
{ | |
public DateTimeOffset Time { get; set; } | |
public string Text { get; set; } | |
} | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var diary = new Diary(); | |
var quit = false; | |
while (!quit) | |
{ | |
var entry = Console.ReadLine(); | |
if (entry?.ToLower() == "bye") | |
{ | |
quit = true; | |
} | |
else | |
{ | |
diary.Add(entry); | |
} | |
} | |
File.WriteAllText("mydiary.json", JsonConvert.SerializeObject(diary)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment