forked from Unity-Technologies/UnityDataTools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExpectedData.cs
More file actions
43 lines (33 loc) · 1.08 KB
/
Copy pathExpectedData.cs
File metadata and controls
43 lines (33 loc) · 1.08 KB
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
40
41
42
43
using System.Collections.Generic;
using System.IO;
using Newtonsoft.Json;
namespace UnityDataTools.TestCommon;
public class ExpectedData
{
private Dictionary<string, object> m_ExpectedValues = new();
public void Add(string key, object value)
{
m_ExpectedValues[key] = value;
}
public object Get(string key)
{
return m_ExpectedValues[key];
}
public void Save(string path)
{
var settings = new JsonSerializerSettings();
settings.TypeNameHandling = TypeNameHandling.All;
File.WriteAllText(Path.Combine(path, "ExpectedValues.json"), JsonConvert.SerializeObject(m_ExpectedValues, Formatting.Indented, settings));
}
public void Load(string path)
{
path = Path.Combine(path, "ExpectedValues.json");
if (!File.Exists(path))
{
return;
}
var settings = new JsonSerializerSettings();
settings.TypeNameHandling = TypeNameHandling.All;
m_ExpectedValues = JsonConvert.DeserializeObject<Dictionary<string, object>>(File.ReadAllText(path), settings);
}
}