-
Notifications
You must be signed in to change notification settings - Fork 3
/
Program.cs
104 lines (87 loc) · 3.08 KB
/
Program.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
using Config4Net.Core;
using Config4Net.Types;
using Config4Net.UI;
using Config4Net.UI.Containers;
using Config4Net.UI.Editors;
using Config4Net.UI.WinForms;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
namespace ExampleApp
{
internal static class Program
{
[STAThread]
private static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
// Load winform implementation
new WinFormFlatformLoader().Load();
// Load config from file or memory
var girlfriend = Config.Default.Get<GirlfriendSettings>();
// Build UI from config instance
var window = UiManager.Default.Build<IWindowContainer>(girlfriend);
Config.Default.Get<GirlfriendSettings>();
Application.Run((Form)window);
}
[Config]
private class GirlfriendSettings
{
[Showable]
public string Name { get; set; }
[Showable]
public int Age { get; set; }
[Showable]
public Color HairColor { get; set; }
[Showable]
public Contact Contact { get; set; }
[Showable]
public Note Note { get; set; }
}
private class Contact
{
[Showable]
[Memo(VerticalScroll = true, Height = 50)]
public string Address { get; set; }
[Showable(Description = "Don't forget it!!")]
public string Phone { get; set; }
}
private class Note
{
[Showable(ComponentType = typeof(IFilePickerEditor))]
public string Avatar { get; set; }
[Showable(ComponentType = typeof(ISelectEditor))]
[Select(typeof(FavoriteSelectFactory))]
public Favorite FavoriteType { get; set; }
[Showable]
public bool DoesSheComplainEveryday { get; set; }
[Showable]
public bool IsSheLazy { get; set; }
[Showable(ComponentType = typeof(ITextEditor))]
public IList<string> Hate { get; set; }
}
private class Favorite
{
public string Name { get; set; }
public string Note { get; set; }
public override string ToString()
{
return Name;
}
}
private class FavoriteSelectFactory : ISelectFactory
{
public Select Create()
{
return new Select.Builder<Favorite>()
.AddOption(new Favorite { Name = "Makeup", Note = "Always compliment her beautiful" })
.AddOption(new Favorite { Name = "Eating", Note = "Remember all the sidewalk cafes" })
.AddOption(new Favorite { Name = "Sport", Note = "Take her to the gym every day" })
.AddOption(new Favorite { Name = "Shopping", Note = "Hummmn!!! What should I do?" })
.Build();
}
}
}
}