-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathContractParser.cs
More file actions
52 lines (43 loc) · 1.39 KB
/
ContractParser.cs
File metadata and controls
52 lines (43 loc) · 1.39 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
44
45
46
47
48
49
50
51
52
using System.Collections.Generic;
using System.IO;
using System.Text;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using Solidoc.Models;
using Solidoc.Utility;
namespace Solidoc
{
public sealed class ContractParser
{
public ContractParser(string buildDirectory)
{
this.BuildDirectory = buildDirectory;
}
private string BuildDirectory { get; }
public IEnumerable<Contract> Parse()
{
var directory = new DirectoryInfo(this.BuildDirectory);
if (!directory.Exists)
{
ConsoleUtility.WriteException(string.Format(I18N.InvalidDirectory, string.Join(" ", directory.FullName)));
yield return null;
}
var files = directory.GetFiles("*.json");
foreach (var file in files)
{
var contract = Parse(file.FullName);
yield return contract;
}
}
private static Contract Parse(string path)
{
var settings = new JsonSerializerSettings
{
ContractResolver = new CamelCasePropertyNamesContractResolver()
};
string contents = File.ReadAllText(path, new UTF8Encoding(false));
var parsed = JsonConvert.DeserializeObject<Contract>(contents, settings);
return parsed;
}
}
}