forked from fdorg/flashdevelop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReflection.cs
More file actions
85 lines (79 loc) · 2.43 KB
/
Reflection.cs
File metadata and controls
85 lines (79 loc) · 2.43 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
using System;
using System.Drawing;
using System.Reflection;
using PluginCore;
using PluginCore.Managers;
using ScintillaNet.Enums;
namespace FlashDevelop.Settings
{
public partial class SettingObject : ISettings
{
/// <summary>
/// Sets a value of a setting
/// </summary>
public void SetValue(String name, Object value)
{
try
{
Type type = this.GetType();
PropertyInfo info = type.GetProperty(name);
info.SetValue(this, value, null);
}
catch (Exception ex)
{
ErrorManager.ShowError(ex);
}
}
/// <summary>
/// Gets a value of a setting as an object
/// </summary>
public Object GetValue(String name)
{
try
{
Type type = this.GetType();
PropertyInfo info = type.GetProperty(name);
return info.GetValue(this, null);
}
catch (Exception ex)
{
ErrorManager.ShowError(ex);
return null;
}
}
/// <summary>
/// Ensures that the values of the settings are not null
/// </summary>
public static void EnsureValidity(SettingObject settings)
{
try
{
SettingObject defaults = GetDefaultSettings();
PropertyInfo[] properties = settings.GetType().GetProperties();
foreach (PropertyInfo property in properties)
{
Object current = settings.GetValue(property.Name);
if (current == null || (current is Color && (Color)current == Color.Empty))
{
Object value = defaults.GetValue(property.Name);
settings.SetValue(property.Name, value);
}
}
}
catch (Exception ex)
{
ErrorManager.ShowError(ex);
}
}
/// <summary>
/// Gets a fresh copy of the settings
/// </summary>
public static SettingObject GetDefaultSettings()
{
SettingObject settings = new SettingObject();
settings.IndentView = IndentView.Real;
settings.DefaultFont = SystemFonts.MenuFont;
return settings;
}
}
}