C# プロパティ グリッドについて質問があります。
public enum xxx
{
[Browsable(true)]
aaa,
[Browsable(false)]
bbb,
[Browsable(true)]
ccc,
}
public class testObject {
public xxx temp;
public xxx test {
get { return temp; }
set { temp = value; }
}
実行時に参照可能属性を変更するにはどうすればよいですか?
たとえば、btn1 が押されたときに、次のように、browsable 属性をすべて false に設定します。
private void button1_Click(object sender, RoutedEventArgs e)
{
object[] browsable;
Type type = typeof(xxx);
FieldInfo[] fieldInfos = type.GetFields();
foreach (FieldInfo fieldInfo in fieldInfos)
{
browsable = fieldInfo.GetCustomAttributes(typeof(BrowsableAttribute), false);
if (browsable.Length == 1)
{
BrowsableAttribute brAttr = (BrowsableAttribute)browsable[0];
fieldInfo.SetValue(brAttr, false);
}
}
}
しかし、それはエラーを引き起こします。