-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathSettingsContainer.cs
54 lines (46 loc) · 1.76 KB
/
SettingsContainer.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using System;
using System.Linq;
using GitUIPluginInterfaces;
namespace GitTfs.GitExtensions.Plugin
{
public class SettingsContainer
{
private readonly ISettingsSource _container;
public SettingsContainer(ISettingsSource container)
{
_container = container;
}
public string TfsRemote
{
get { return _container.GetValue(SettingKeys.TfsRemote, null , x => x); }
set { _container.SetValue(SettingKeys.TfsRemote, value, x => x); }
}
public PullSetting? PullSetting
{
get { return GetEnumSettingValue<PullSetting>(SettingKeys.Pull); }
set { SetEnumSettingValue(SettingKeys.Pull, value); }
}
public PushSetting? PushSetting
{
get { return GetEnumSettingValue<PushSetting>(SettingKeys.Push); }
set { SetEnumSettingValue(SettingKeys.Push, value); }
}
public ShelveSettingsContainer ShelveSettings
{
get { return new ShelveSettingsContainer(_container); }
}
private T? GetEnumSettingValue<T>(string key)
where T : struct
{
var type = typeof (T);
return _container.GetValue(key, default(T), x => (from name in Enum.GetNames(type)
where name == x
select (T?) Enum.Parse(type, name)).FirstOrDefault());
}
private void SetEnumSettingValue<T>(string key, T? value)
where T : struct
{
_container.SetValue(key, value, x => x.HasValue ? x.ToString() : string.Empty);
}
}
}