29 lines
911 B
C#
29 lines
911 B
C#
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) {
|
|
_target = target ?? throw new ArgumentNullException("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));
|
|
}
|
|
}
|
|
}
|