This repository has been archived by the owner on Jul 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SettingsService.cs
80 lines (59 loc) · 1.98 KB
/
SettingsService.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
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
using AppSettingsManagement;
using AppSettingsManagement.Converters;
using AppSettingsManagement.Windows;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AppSettingsManagementSample.Services;
internal partial class SettingsService : SettingsContainer
{
static readonly ISettingsStorage Provider = new WinRTSettingsStorage();
#region Settings
// Test strings
[SettingItem(typeof(string), "TestString")]
[SettingItem(typeof(string), "TestStringWithDefault", Default = "DEFAULT STRING")]
// Test ints
[SettingItem(typeof(int), "TestInt")] // Used to test properties without default
[SettingItem(typeof(int), "TestIntWithDefault", Default = 100)]
// Test enums
[SettingItem(typeof(Theme), "Theme", Default = Theme.Default)]
[SettingItem(typeof(TestEnum), "TestEnum")]
// Test lists
[SettingsCollection(typeof(int), "IntList")]
// Test containers
[SettingsContainer(typeof(AccountInformation), "ActiveAccount")] // Composite values
// Test converters
[SettingItem(typeof(Student), "Student", Converter = typeof(JsonStringConverter<Student>))]
[SettingsCollection(typeof(Student), "Students", Converter = typeof(JsonStringConverter<Student>))]
#endregion
public SettingsService() : base(Provider) { }
}
public enum Theme
{
Bright,
Dark,
Default
}
enum TestEnum : byte
{
A,
B,
C
}
internal partial class AccountInformation : SettingsContainer
{
#region Settings
[SettingItem(typeof(string), "Username", Default = "a")]
[SettingItem(typeof(string), "Password", Default = "b")]
#endregion
public AccountInformation(ISettingsStorage storage, string name, ISettingsContainer parent) : base(storage, name, parent) { }
}
internal class Student
{
public string Name { get; set; } = "";
public int Age { get; set; }
public char Gender { get; set; } = 'M';
public string Year { get; set; } = "";
}