Rewrite property panel to adapt to ruleset config.
This commit is contained in:
29
Assets/Cryville/Crtr/Config/IPropertyMasterAdapter.cs
Normal file
29
Assets/Cryville/Crtr/Config/IPropertyMasterAdapter.cs
Normal 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));
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user