Skip to content

Instantly share code, notes, and snippets.

@voquanghoa voquanghoa/Save.cs
Created Nov 27, 2017

Embed
What would you like to do?
public static void SaveJson<T>(List<T> data, string directory)
{
if (!Directory.Exists(directory))
{
Directory.CreateDirectory(directory);
}
var fileName = $"{typeof(T).Name}s.json";
var filePath = Path.Combine(directory, fileName);
var json = JsonConvert.SerializeObject(data);
File.WriteAllText(filePath, json);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.