Rewrite property panel to adapt to ruleset config.

This commit is contained in:
2023-07-27 22:07:20 +08:00
parent 9b091a0084
commit bc51a45df8
39 changed files with 825 additions and 298 deletions

View File

@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
namespace Cryville.Crtr.Config {
public interface IPropertyMasterAdapter {
string DefaultCategory { get; }
IEnumerable<IPropertyAdapter> GetProperties();
}
public class DefaultPropertyMasterAdapter : IPropertyMasterAdapter {
readonly object _target;
public DefaultPropertyMasterAdapter(object target) {
if (target == null) throw new ArgumentNullException("target");
_target = target;
}
public string DefaultCategory { get { return "miscellaneous"; } }
public IEnumerable<IPropertyAdapter> GetProperties() {
return _target.GetType().GetProperties().Where(p => {
var attrs = p.GetCustomAttributes(typeof(BrowsableAttribute), true);
if (attrs.Length == 0) return true;
else return ((BrowsableAttribute)attrs.Single()).Browsable;
}).Select(p => new DefaultPropertyAdapter(_target, p));
}
}
}