Code cleanup.

This commit is contained in:
2023-07-28 13:33:23 +08:00
parent 957270c41a
commit 799b1e12da

View File

@@ -28,14 +28,10 @@ namespace Cryville.Crtr.Config {
public class DefaultPropertyAdapter : IPropertyAdapter { public class DefaultPropertyAdapter : IPropertyAdapter {
readonly object _target; readonly object _target;
readonly PropertyInfo _prop; readonly PropertyInfo _prop;
readonly string m_category; public string Category { get; private set; }
public string Category { get { return m_category; } } public string Name { get; private set; }
readonly string m_name; public PropertyType Type { get; private set; }
public string Name { get { return m_name; } } public object[] Range { get; private set; }
readonly PropertyType m_type = PropertyType.Unknown;
public PropertyType Type { get { return m_type; } }
readonly object[] m_range;
public object[] Range { get { return m_range; } }
public object GetValue() { return _prop.GetValue(_target, null); } public object GetValue() { return _prop.GetValue(_target, null); }
public void SetValue(object value) { _prop.SetValue(_target, value, null); } public void SetValue(object value) { _prop.SetValue(_target, value, null); }
@@ -67,18 +63,18 @@ namespace Cryville.Crtr.Config {
_target = target; _target = target;
_prop = prop; _prop = prop;
var attrs = prop.GetCustomAttributes(typeof(CategoryAttribute), true); var attrs = prop.GetCustomAttributes(typeof(CategoryAttribute), true);
if (attrs.Length > 0) m_category = ((CategoryAttribute)attrs.Single()).Category; if (attrs.Length > 0) Category = ((CategoryAttribute)attrs.Single()).Category;
m_name = prop.Name; Name = prop.Name;
if (prop.PropertyType == typeof(bool)) m_type = PropertyType.Boolean; if (prop.PropertyType == typeof(bool)) Type = PropertyType.Boolean;
else if (prop.PropertyType == typeof(char)) throw new NotSupportedException(); else if (prop.PropertyType == typeof(char)) throw new NotSupportedException();
else if (prop.PropertyType.IsPrimitive) { else if (prop.PropertyType.IsPrimitive) {
m_type = prop.GetCustomAttributes(typeof(StepAttribute), true).Length > 0 Type = prop.GetCustomAttributes(typeof(StepAttribute), true).Length > 0
? PropertyType.NumberStepped ? PropertyType.NumberStepped
: PropertyType.Number; : PropertyType.Number;
var attr = prop.GetCustomAttributes(typeof(RangeAttribute), true); var attr = prop.GetCustomAttributes(typeof(RangeAttribute), true);
if (attr.Length > 0) { if (attr.Length > 0) {
var u = (RangeAttribute)attr.Single(); var u = (RangeAttribute)attr.Single();
m_range = new object[] { u.Min, u.Max }; Range = new object[] { u.Min, u.Max };
} }
attr = prop.GetCustomAttributes(typeof(PrecisionAttribute), true); attr = prop.GetCustomAttributes(typeof(PrecisionAttribute), true);
if (attr.Length > 0) { if (attr.Length > 0) {
@@ -95,7 +91,7 @@ namespace Cryville.Crtr.Config {
_logarithmic = true; _logarithmic = true;
} }
} }
else if (prop.PropertyType == typeof(string)) m_type = PropertyType.String; else if (prop.PropertyType == typeof(string)) Type = PropertyType.String;
else return; else return;
} }
} }