2019-02-12 22:13:09 -05:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2020-06-22 19:12:25 -04:00
|
|
|
|
using System.Drawing;
|
2019-02-12 22:13:09 -05:00
|
|
|
|
using System.Globalization;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using Mesen.GUI.Controls;
|
|
|
|
|
using Mesen.GUI.Forms.Config;
|
2019-03-07 20:12:32 -05:00
|
|
|
|
using Mesen.GUI.Utilities;
|
2019-02-12 22:13:09 -05:00
|
|
|
|
|
|
|
|
|
namespace Mesen.GUI.Forms
|
|
|
|
|
{
|
|
|
|
|
public class EntityBinder
|
|
|
|
|
{
|
2019-02-15 21:33:13 -05:00
|
|
|
|
private Dictionary<string, object> _bindings = new Dictionary<string, object>();
|
2020-10-12 16:51:04 +03:00
|
|
|
|
private Dictionary<string, EventHandler> _bindedHandlers = new Dictionary<string, EventHandler>();
|
2019-02-12 22:13:09 -05:00
|
|
|
|
private Dictionary<string, eNumberFormat> _fieldFormat = new Dictionary<string, eNumberFormat>();
|
|
|
|
|
private Dictionary<string, FieldInfoWrapper> _fieldInfo = null;
|
|
|
|
|
|
|
|
|
|
public object Entity { get; set; }
|
|
|
|
|
|
|
|
|
|
protected virtual Type BindedType
|
|
|
|
|
{
|
|
|
|
|
get { return Entity.GetType(); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool Updating { get; private set; }
|
|
|
|
|
|
2020-10-12 16:51:04 +03:00
|
|
|
|
public void AddBinding(string fieldName, object bindedField, eNumberFormat format = eNumberFormat.Default, EventHandler onEditHandler = null)
|
2019-02-12 22:13:09 -05:00
|
|
|
|
{
|
|
|
|
|
if(BindedType == null) {
|
|
|
|
|
throw new Exception("Need to override BindedType to use bindings");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(_fieldInfo == null) {
|
|
|
|
|
_fieldInfo = new Dictionary<string, FieldInfoWrapper>();
|
|
|
|
|
PropertyInfo[] properties = BindedType.GetProperties();
|
|
|
|
|
foreach(PropertyInfo info in properties) {
|
|
|
|
|
_fieldInfo[info.Name] = new FieldInfoWrapper(info);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FieldInfo[] members = BindedType.GetFields();
|
|
|
|
|
foreach(FieldInfo info in members) {
|
|
|
|
|
_fieldInfo[info.Name] = new FieldInfoWrapper(info);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(_fieldInfo.ContainsKey(fieldName)) {
|
|
|
|
|
Type fieldType = _fieldInfo[fieldName].FieldType;
|
|
|
|
|
if(fieldType.IsSubclassOf(typeof(Enum)) && bindedField is ComboBox) {
|
|
|
|
|
BaseConfigForm.InitializeComboBox(((ComboBox)bindedField), fieldType);
|
|
|
|
|
}
|
|
|
|
|
_bindings[fieldName] = bindedField;
|
2020-10-12 16:51:04 +03:00
|
|
|
|
_bindedHandlers[fieldName] = onEditHandler;
|
|
|
|
|
|
|
|
|
|
if(bindedField is TextBox) {
|
|
|
|
|
((TextBox)bindedField).Leave += onEditHandler;
|
|
|
|
|
} else if(bindedField is ctrlPathSelection) {
|
|
|
|
|
((ctrlPathSelection)bindedField).Leave += onEditHandler;
|
|
|
|
|
} else if(bindedField is CheckBox) {
|
|
|
|
|
((CheckBox)bindedField).CheckedChanged += onEditHandler;
|
|
|
|
|
} else if(bindedField is ToolStripMenuItem) {
|
|
|
|
|
((ToolStripMenuItem)bindedField).CheckedChanged += onEditHandler;
|
|
|
|
|
} else if(bindedField is ctrlRiskyOption) {
|
|
|
|
|
((ctrlRiskyOption)bindedField).Click += onEditHandler;
|
|
|
|
|
} else if(bindedField is RadioButton) {
|
|
|
|
|
((RadioButton)bindedField).CheckedChanged += onEditHandler;
|
|
|
|
|
} else if(bindedField is PictureBox) {
|
|
|
|
|
((PictureBox)bindedField).BackColorChanged += onEditHandler;
|
|
|
|
|
} else if(bindedField is Panel) {
|
|
|
|
|
FieldInfoWrapper field = _fieldInfo[fieldName];
|
|
|
|
|
object value = field.GetValue(this.Entity);
|
|
|
|
|
RadioButton radio = ((Panel)bindedField).Controls.OfType<RadioButton>().FirstOrDefault(r => r.Tag.Equals(value));
|
|
|
|
|
if(radio != null) {
|
|
|
|
|
radio.CheckedChanged += onEditHandler;
|
|
|
|
|
} else {
|
|
|
|
|
throw new Exception("No radio button matching value found");
|
|
|
|
|
}
|
|
|
|
|
} else if(bindedField is ctrlTrackbar) {
|
|
|
|
|
((ctrlTrackbar)bindedField).ValueChanged += onEditHandler;
|
|
|
|
|
} else if(bindedField is ctrlHorizontalTrackbar) {
|
|
|
|
|
((ctrlHorizontalTrackbar)bindedField).ValueChanged += onEditHandler;
|
|
|
|
|
} else if(bindedField is TrackBar) {
|
|
|
|
|
((TrackBar)bindedField).ValueChanged += onEditHandler;
|
|
|
|
|
} else if(bindedField is MesenNumericUpDown) {
|
|
|
|
|
((MesenNumericUpDown)bindedField).ValueChanged += onEditHandler;
|
|
|
|
|
} else if(bindedField is ComboBox) {
|
|
|
|
|
((ComboBox)bindedField).SelectedIndexChanged += onEditHandler;
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-12 22:13:09 -05:00
|
|
|
|
_fieldFormat[fieldName] = format;
|
|
|
|
|
} else {
|
|
|
|
|
throw new Exception("Invalid field name");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void UpdateUI()
|
|
|
|
|
{
|
|
|
|
|
this.Updating = true;
|
|
|
|
|
|
2019-02-15 21:33:13 -05:00
|
|
|
|
foreach(KeyValuePair<string, object> kvp in _bindings) {
|
2019-02-12 22:13:09 -05:00
|
|
|
|
if(!_fieldInfo.ContainsKey(kvp.Key)) {
|
|
|
|
|
throw new Exception("Invalid binding key");
|
|
|
|
|
} else {
|
|
|
|
|
FieldInfoWrapper field = _fieldInfo[kvp.Key];
|
|
|
|
|
eNumberFormat format = _fieldFormat[kvp.Key];
|
|
|
|
|
object value = field.GetValue(this.Entity);
|
|
|
|
|
if(kvp.Value is TextBox) {
|
|
|
|
|
if(value is IFormattable) {
|
2019-02-15 21:33:13 -05:00
|
|
|
|
((TextBox)kvp.Value).Text = ((IFormattable)value).ToString(format == eNumberFormat.Decimal ? "" : "X", System.Globalization.CultureInfo.InvariantCulture);
|
2019-02-12 22:13:09 -05:00
|
|
|
|
} else {
|
2019-02-15 21:33:13 -05:00
|
|
|
|
((TextBox)kvp.Value).Text = value == null ? "" : ((string)value).Replace(Environment.NewLine, "\n").Replace("\n", Environment.NewLine);
|
2019-02-12 22:13:09 -05:00
|
|
|
|
}
|
|
|
|
|
} else if(kvp.Value is ctrlPathSelection) {
|
2019-02-15 21:33:13 -05:00
|
|
|
|
((ctrlPathSelection)kvp.Value).Text = (string)value;
|
2019-02-12 22:13:09 -05:00
|
|
|
|
} else if(kvp.Value is CheckBox) {
|
|
|
|
|
((CheckBox)kvp.Value).Checked = Convert.ToBoolean(value);
|
2019-02-15 21:33:13 -05:00
|
|
|
|
} else if(kvp.Value is ToolStripMenuItem) {
|
|
|
|
|
((ToolStripMenuItem)kvp.Value).Checked = Convert.ToBoolean(value);
|
2019-02-12 22:13:09 -05:00
|
|
|
|
} else if(kvp.Value is ctrlRiskyOption) {
|
|
|
|
|
((ctrlRiskyOption)kvp.Value).Checked = Convert.ToBoolean(value);
|
|
|
|
|
} else if(kvp.Value is RadioButton) {
|
|
|
|
|
((RadioButton)kvp.Value).Checked = (bool)value;
|
2019-03-07 20:12:32 -05:00
|
|
|
|
} else if(kvp.Value is PictureBox) {
|
2020-06-22 19:12:25 -04:00
|
|
|
|
if(value is UInt32) {
|
|
|
|
|
((PictureBox)kvp.Value).BackColor = Color.FromArgb((int)(0xFF000000 | (UInt32)value));
|
|
|
|
|
} else {
|
|
|
|
|
((PictureBox)kvp.Value).BackColor = (XmlColor)value;
|
|
|
|
|
}
|
2019-02-12 22:13:09 -05:00
|
|
|
|
} else if(kvp.Value is Panel) {
|
2019-02-15 21:33:13 -05:00
|
|
|
|
RadioButton radio = ((Panel)kvp.Value).Controls.OfType<RadioButton>().FirstOrDefault(r => r.Tag.Equals(value));
|
2019-02-12 22:13:09 -05:00
|
|
|
|
if(radio != null) {
|
|
|
|
|
radio.Checked = true;
|
|
|
|
|
} else {
|
|
|
|
|
throw new Exception("No radio button matching value found");
|
|
|
|
|
}
|
|
|
|
|
} else if(kvp.Value is ctrlTrackbar) {
|
2019-03-10 17:39:14 -04:00
|
|
|
|
if(field.FieldType == typeof(double)) {
|
|
|
|
|
((ctrlTrackbar)kvp.Value).Value = (int)((double)value * 100);
|
|
|
|
|
} else if(field.FieldType == typeof(Int32)) {
|
2019-02-12 22:13:09 -05:00
|
|
|
|
((ctrlTrackbar)kvp.Value).Value = (int)value;
|
|
|
|
|
} else {
|
|
|
|
|
((ctrlTrackbar)kvp.Value).Value = (int)(uint)value;
|
|
|
|
|
}
|
|
|
|
|
} else if(kvp.Value is ctrlHorizontalTrackbar) {
|
2019-03-10 11:12:50 -04:00
|
|
|
|
if(field.FieldType == typeof(double)) {
|
|
|
|
|
((ctrlHorizontalTrackbar)kvp.Value).Value = (int)((double)value * 100);
|
2019-03-10 17:39:14 -04:00
|
|
|
|
} else if(field.FieldType == typeof(UInt32)) {
|
|
|
|
|
((ctrlHorizontalTrackbar)kvp.Value).Value = (int)(uint)value;
|
2019-03-10 11:12:50 -04:00
|
|
|
|
} else {
|
|
|
|
|
((ctrlHorizontalTrackbar)kvp.Value).Value = (int)value;
|
|
|
|
|
}
|
2019-02-12 22:13:09 -05:00
|
|
|
|
} else if(kvp.Value is TrackBar) {
|
|
|
|
|
if(field.FieldType == typeof(Int32)) {
|
|
|
|
|
((TrackBar)kvp.Value).Value = (int)value;
|
|
|
|
|
} else {
|
|
|
|
|
((TrackBar)kvp.Value).Value = (int)(uint)value;
|
|
|
|
|
}
|
|
|
|
|
} else if(kvp.Value is MesenNumericUpDown) {
|
|
|
|
|
MesenNumericUpDown nud = kvp.Value as MesenNumericUpDown;
|
|
|
|
|
decimal val;
|
|
|
|
|
if(field.FieldType == typeof(UInt32)) {
|
|
|
|
|
val = (UInt32)value;
|
|
|
|
|
} else if(field.FieldType == typeof(Int32)) {
|
|
|
|
|
val = (Int32)value;
|
|
|
|
|
} else {
|
|
|
|
|
val = (decimal)(double)value;
|
|
|
|
|
}
|
|
|
|
|
val = Math.Min(Math.Max(val, nud.Minimum), nud.Maximum);
|
|
|
|
|
nud.Value = val;
|
|
|
|
|
} else if(kvp.Value is ComboBox) {
|
|
|
|
|
ComboBox combo = kvp.Value as ComboBox;
|
|
|
|
|
if(value is Enum) {
|
|
|
|
|
combo.SelectedItem = ResourceHelper.GetEnumText((Enum)value);
|
|
|
|
|
} else if(field.FieldType == typeof(UInt32)) {
|
|
|
|
|
for(int i = 0, len = combo.Items.Count; i < len; i++) {
|
|
|
|
|
UInt32 numericValue;
|
|
|
|
|
string item = Regex.Replace(combo.Items[i].ToString(), "[^0-9]", "");
|
|
|
|
|
if(UInt32.TryParse(item, out numericValue)) {
|
|
|
|
|
if(numericValue == (UInt32)value) {
|
|
|
|
|
combo.SelectedIndex = i;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else if(field.FieldType == typeof(string)) {
|
|
|
|
|
combo.SelectedItem = value;
|
|
|
|
|
if(combo.SelectedIndex < 0 && combo.Items.Count > 0) {
|
|
|
|
|
combo.SelectedIndex = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.Updating = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void UpdateObject()
|
|
|
|
|
{
|
2019-02-15 21:33:13 -05:00
|
|
|
|
foreach(KeyValuePair<string, object> kvp in _bindings) {
|
2019-02-12 22:13:09 -05:00
|
|
|
|
if(!_fieldInfo.ContainsKey(kvp.Key)) {
|
|
|
|
|
throw new Exception("Invalid binding key");
|
|
|
|
|
} else {
|
|
|
|
|
try {
|
|
|
|
|
FieldInfoWrapper field = _fieldInfo[kvp.Key];
|
|
|
|
|
eNumberFormat format = _fieldFormat[kvp.Key];
|
|
|
|
|
if(kvp.Value is TextBox) {
|
2019-02-15 21:33:13 -05:00
|
|
|
|
object value = ((TextBox)kvp.Value).Text;
|
2019-02-12 22:13:09 -05:00
|
|
|
|
NumberStyles numberStyle = format == eNumberFormat.Decimal ? NumberStyles.Integer : NumberStyles.HexNumber;
|
|
|
|
|
if(field.FieldType != typeof(string)) {
|
|
|
|
|
value = ((string)value).Trim().Replace("$", "").Replace("0x", "");
|
|
|
|
|
if(string.IsNullOrWhiteSpace((string)value)) {
|
|
|
|
|
value = "0";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(field.FieldType == typeof(UInt32)) {
|
|
|
|
|
UInt32 result;
|
|
|
|
|
if(!UInt32.TryParse((string)value, numberStyle, null, out result)) {
|
|
|
|
|
continue; //Invalid value, ignore it
|
|
|
|
|
}
|
|
|
|
|
value = result;
|
|
|
|
|
} else if(field.FieldType == typeof(Int32)) {
|
|
|
|
|
Int32 result;
|
|
|
|
|
if(!Int32.TryParse((string)value, numberStyle, null, out result)) {
|
|
|
|
|
continue; //Invalid value, ignore it
|
|
|
|
|
}
|
|
|
|
|
value = result;
|
|
|
|
|
} else if(field.FieldType == typeof(Byte)) {
|
|
|
|
|
Byte result;
|
|
|
|
|
if(!Byte.TryParse((string)value, numberStyle, null, out result)) {
|
|
|
|
|
continue; //Invalid value, ignore it
|
|
|
|
|
}
|
|
|
|
|
value = result;
|
|
|
|
|
} else if(field.FieldType == typeof(UInt16)) {
|
|
|
|
|
UInt16 result;
|
|
|
|
|
if(!UInt16.TryParse((string)value, numberStyle, null, out result)) {
|
|
|
|
|
continue; //Invalid value, ignore it
|
|
|
|
|
}
|
|
|
|
|
value = result;
|
|
|
|
|
} else if(field.FieldType == typeof(UInt64)) {
|
|
|
|
|
UInt64 result;
|
|
|
|
|
if(!UInt64.TryParse((string)value, numberStyle, null, out result)) {
|
|
|
|
|
continue; //Invalid value, ignore it
|
|
|
|
|
}
|
|
|
|
|
value = result;
|
|
|
|
|
} else if(field.FieldType == typeof(Int64)) {
|
|
|
|
|
Int64 result;
|
|
|
|
|
if(!Int64.TryParse((string)value, numberStyle, null, out result)) {
|
|
|
|
|
continue; //Invalid value, ignore it
|
|
|
|
|
}
|
|
|
|
|
value = result;
|
|
|
|
|
}
|
|
|
|
|
field.SetValue(Entity, value);
|
|
|
|
|
} else if(kvp.Value is ctrlPathSelection) {
|
|
|
|
|
field.SetValue(Entity, ((ctrlPathSelection)kvp.Value).Text);
|
|
|
|
|
} else if(kvp.Value is CheckBox) {
|
|
|
|
|
if(field.FieldType == typeof(bool)) {
|
|
|
|
|
field.SetValue(Entity, ((CheckBox)kvp.Value).Checked);
|
|
|
|
|
} else if(field.FieldType == typeof(byte)) {
|
|
|
|
|
field.SetValue(Entity, ((CheckBox)kvp.Value).Checked ? (byte)1 : (byte)0);
|
|
|
|
|
}
|
2019-02-15 21:33:13 -05:00
|
|
|
|
} else if(kvp.Value is ToolStripMenuItem) {
|
|
|
|
|
if(field.FieldType == typeof(bool)) {
|
|
|
|
|
field.SetValue(Entity, ((ToolStripMenuItem)kvp.Value).Checked);
|
|
|
|
|
}
|
2019-02-12 22:13:09 -05:00
|
|
|
|
} else if(kvp.Value is ctrlRiskyOption) {
|
|
|
|
|
if(field.FieldType == typeof(bool)) {
|
|
|
|
|
field.SetValue(Entity, ((ctrlRiskyOption)kvp.Value).Checked);
|
|
|
|
|
} else if(field.FieldType == typeof(byte)) {
|
|
|
|
|
field.SetValue(Entity, ((ctrlRiskyOption)kvp.Value).Checked ? (byte)1 : (byte)0);
|
|
|
|
|
}
|
|
|
|
|
} else if(kvp.Value is RadioButton) {
|
|
|
|
|
field.SetValue(Entity, ((RadioButton)kvp.Value).Checked);
|
2019-03-07 20:12:32 -05:00
|
|
|
|
} else if(kvp.Value is PictureBox) {
|
2020-06-22 19:12:25 -04:00
|
|
|
|
if(field.FieldType == typeof(UInt32)) {
|
|
|
|
|
field.SetValue(Entity, (UInt32)((PictureBox)kvp.Value).BackColor.ToArgb() & 0xFFFFFF);
|
|
|
|
|
} else {
|
|
|
|
|
field.SetValue(Entity, (XmlColor)((PictureBox)kvp.Value).BackColor);
|
|
|
|
|
}
|
2019-02-12 22:13:09 -05:00
|
|
|
|
} else if(kvp.Value is Panel) {
|
2019-02-15 21:33:13 -05:00
|
|
|
|
field.SetValue(Entity, ((Panel)kvp.Value).Controls.OfType<RadioButton>().FirstOrDefault(r => r.Checked).Tag);
|
2019-02-12 22:13:09 -05:00
|
|
|
|
} else if(kvp.Value is ctrlTrackbar) {
|
2019-03-10 17:39:14 -04:00
|
|
|
|
if(field.FieldType == typeof(double)) {
|
|
|
|
|
field.SetValue(Entity, ((ctrlTrackbar)kvp.Value).Value / 100.0);
|
|
|
|
|
} else if(field.FieldType == typeof(Int32)) {
|
2019-02-12 22:13:09 -05:00
|
|
|
|
field.SetValue(Entity, (Int32)((ctrlTrackbar)kvp.Value).Value);
|
|
|
|
|
} else {
|
|
|
|
|
field.SetValue(Entity, (UInt32)((ctrlTrackbar)kvp.Value).Value);
|
|
|
|
|
}
|
|
|
|
|
} else if(kvp.Value is ctrlHorizontalTrackbar) {
|
2019-03-10 11:12:50 -04:00
|
|
|
|
if(field.FieldType == typeof(double)) {
|
|
|
|
|
field.SetValue(Entity, ((ctrlHorizontalTrackbar)kvp.Value).Value / 100.0);
|
2019-03-10 17:39:14 -04:00
|
|
|
|
} else if(field.FieldType == typeof(UInt32)) {
|
|
|
|
|
field.SetValue(Entity, (UInt32)((ctrlHorizontalTrackbar)kvp.Value).Value);
|
2019-03-10 11:12:50 -04:00
|
|
|
|
} else {
|
|
|
|
|
field.SetValue(Entity, (Int32)((ctrlHorizontalTrackbar)kvp.Value).Value);
|
|
|
|
|
}
|
2019-02-12 22:13:09 -05:00
|
|
|
|
} else if(kvp.Value is TrackBar) {
|
|
|
|
|
if(field.FieldType == typeof(Int32)) {
|
|
|
|
|
field.SetValue(Entity, ((TrackBar)kvp.Value).Value);
|
|
|
|
|
} else {
|
|
|
|
|
field.SetValue(Entity, (UInt32)((TrackBar)kvp.Value).Value);
|
|
|
|
|
}
|
|
|
|
|
} else if(kvp.Value is MesenNumericUpDown) {
|
|
|
|
|
if(field.FieldType == typeof(UInt32)) {
|
|
|
|
|
field.SetValue(Entity, (UInt32)((MesenNumericUpDown)kvp.Value).Value);
|
|
|
|
|
} else if(field.FieldType == typeof(Int32)) {
|
|
|
|
|
field.SetValue(Entity, (Int32)((MesenNumericUpDown)kvp.Value).Value);
|
|
|
|
|
} else {
|
|
|
|
|
field.SetValue(Entity, (double)((MesenNumericUpDown)kvp.Value).Value);
|
|
|
|
|
}
|
|
|
|
|
} else if(kvp.Value is ComboBox) {
|
|
|
|
|
if(field.FieldType.IsSubclassOf(typeof(Enum))) {
|
|
|
|
|
Enum enumValue = ((ComboBox)kvp.Value).GetEnumValue(field.FieldType);
|
|
|
|
|
if(enumValue != null) {
|
|
|
|
|
field.SetValue(Entity, enumValue);
|
|
|
|
|
}
|
|
|
|
|
} else if(field.FieldType == typeof(UInt32)) {
|
|
|
|
|
UInt32 numericValue;
|
|
|
|
|
string item = Regex.Replace(((ComboBox)kvp.Value).SelectedItem.ToString(), "[^0-9]", "");
|
|
|
|
|
if(UInt32.TryParse(item, out numericValue)) {
|
|
|
|
|
field.SetValue(Entity, numericValue);
|
|
|
|
|
}
|
|
|
|
|
} else if(field.FieldType == typeof(string)) {
|
|
|
|
|
field.SetValue(Entity, ((ComboBox)kvp.Value).SelectedItem);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch {
|
|
|
|
|
//Ignore exceptions caused by bad user input
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private class FieldInfoWrapper
|
|
|
|
|
{
|
|
|
|
|
private FieldInfo _fieldInfo;
|
|
|
|
|
private PropertyInfo _propertyInfo;
|
|
|
|
|
|
|
|
|
|
public FieldInfoWrapper(PropertyInfo info)
|
|
|
|
|
{
|
|
|
|
|
_propertyInfo = info;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public FieldInfoWrapper(FieldInfo info)
|
|
|
|
|
{
|
|
|
|
|
_fieldInfo = info;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Type FieldType
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if(_fieldInfo != null) {
|
|
|
|
|
return _fieldInfo.FieldType;
|
|
|
|
|
} else {
|
|
|
|
|
return _propertyInfo.PropertyType;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetValue(object obj, object value)
|
|
|
|
|
{
|
|
|
|
|
if(_fieldInfo != null) {
|
|
|
|
|
_fieldInfo.SetValue(obj, value);
|
|
|
|
|
} else {
|
|
|
|
|
_propertyInfo.SetValue(obj, value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public object GetValue(object obj)
|
|
|
|
|
{
|
|
|
|
|
if(_fieldInfo != null) {
|
|
|
|
|
return _fieldInfo.GetValue(obj);
|
|
|
|
|
} else {
|
|
|
|
|
return _propertyInfo.GetValue(obj);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public enum eNumberFormat
|
|
|
|
|
{
|
|
|
|
|
Default,
|
|
|
|
|
Hex,
|
|
|
|
|
Decimal,
|
|
|
|
|
}
|
|
|
|
|
}
|