This repository was archived by the owner on Jun 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathPackageSettingsGen.tt
More file actions
86 lines (78 loc) · 2.18 KB
/
PackageSettingsGen.tt
File metadata and controls
86 lines (78 loc) · 2.18 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<#@ template debug="false" hostspecific="true" language="C#" #>
<#@ assembly name="System.Core" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ import namespace="System.IO" #>
<#@ assembly name="$(USERPROFILE)\.nuget\packages\Newtonsoft.Json\6.0.8\lib\net45\Newtonsoft.Json.dll" #>
<#@ import namespace="Newtonsoft.Json.Linq" #>
<#@ output extension=".cs" #>
<#
var file = this.Host.ResolvePath(@"..\..\..\common\settings.json");
var json = JObject.Parse(File.ReadAllText(file));
#>
// This is an automatically generated file, based on settings.json and PackageSettingsGen.tt
/* settings.json content:
<#@ include file="..\..\..\common\settings.json" #>
*/
using GitHub.Settings;
using GitHub.Primitives;
using GitHub.VisualStudio.Helpers;
namespace GitHub.VisualStudio.Settings {
public partial class PackageSettings : NotificationAwareObject, IPackageSettings
{
<#
foreach (var j in json["settings"].Children()) {
var type = j["type"].ToString();
if (type == "object")
type = j["typename"].ToString();
var field = Char.ToLower(j["name"].ToString()[0]) + j["name"].ToString().Substring(1);
#>
<#= type #> <#= field #>;
public <#= type #> <#= j["name"] #>
{
get { return <#= field #>; }
set { <#= field #> = value; this.RaisePropertyChange(); }
}
<#
}
#>
void LoadSettings()
{
<#
foreach (var j in json.Children().Children().Children()) {
if (j["type"].ToString() == "object")
{
#>
<#= j["name"] #> = SimpleJson.DeserializeObject<<#= j["typename"] #>>((string)settingsStore.Read("<#= j["name"] #>", "{}"));
<#
}
else
{
#>
<#= j["name"] #> = (<#= j["type"] #>)settingsStore.Read("<#= j["name"] #>", <#= j["default"] #>);
<#
}
}
#>
}
void SaveSettings()
{
<#
foreach (var j in json.Children().Children().Children()) {
if (j["type"].ToString() == "object")
{
#>
settingsStore.Write("<#= j["name"] #>", SimpleJson.SerializeObject(<#= j["name"] #>));
<#
}
else
{
#>
settingsStore.Write("<#= j["name"] #>", <#= j["name"] #>);
<#
}
}
#>
}
}
}