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 {
readonly object _target;
readonly PropertyInfo _prop;
readonly string m_category;
public string Category { get { return m_category; } }
readonly string m_name;
public string Name { get { return m_name; } }
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 string Category { get; private set; }
public string Name { get; private set; }
public PropertyType Type { get; private set; }
public object[] Range { get; private set; }
public object GetValue() { return _prop.GetValue(_target, null); }
public void SetValue(object value) { _prop.SetValue(_target, value, null); }
@@ -67,18 +63,18 @@ namespace Cryville.Crtr.Config {
_target = target;
_prop = prop;
var attrs = prop.GetCustomAttributes(typeof(CategoryAttribute), true);
if (attrs.Length > 0) m_category = ((CategoryAttribute)attrs.Single()).Category;
m_name = prop.Name;
if (prop.PropertyType == typeof(bool)) m_type = PropertyType.Boolean;
if (attrs.Length > 0) Category = ((CategoryAttribute)attrs.Single()).Category;
Name = prop.Name;
if (prop.PropertyType == typeof(bool)) Type = PropertyType.Boolean;
else if (prop.PropertyType == typeof(char)) throw new NotSupportedException();
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.Number;
var attr = prop.GetCustomAttributes(typeof(RangeAttribute), true);
if (attr.Length > 0) {
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);
if (attr.Length > 0) {
@@ -95,7 +91,7 @@ namespace Cryville.Crtr.Config {
_logarithmic = true;
}
}
else if (prop.PropertyType == typeof(string)) m_type = PropertyType.String;
else if (prop.PropertyType == typeof(string)) Type = PropertyType.String;
else return;
}
}