-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
InputModel.cs
39 lines (36 loc) · 1.04 KB
/
InputModel.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using Newtonsoft.Json;
using System.IO;
namespace RevitAddin.DA.Tester.Models
{
public class InputModel
{
public string Text { get; set; }
public int Sleep { get; set; }
#region JsonConvert
private const string JSON_FILE = "input.json";
public InputModel Load(string jsonPath = JSON_FILE)
{
if (File.Exists(jsonPath))
{
string jsonContents = File.ReadAllText(jsonPath);
return JsonConvert.DeserializeObject<InputModel>(jsonContents);
}
return this;
}
public string Save(string jsonPath = JSON_FILE)
{
string text = JsonConvert.SerializeObject(this);
using (StreamWriter sw = File.CreateText(jsonPath))
{
sw.WriteLine(text);
sw.Close();
}
return text;
}
public override string ToString()
{
return JsonConvert.SerializeObject(this);
}
#endregion
}
}