名前の付いたクラスがCommonKeys.cs
あり、以下のようなプロパティが含まれています。
public class Test
{
private SolidBrush _backgroundbrush;
[CategoryAttribute("Default")]
public SolidBrush BackgroundBrush
{
get
{
return this._backgroundbrush;
}
set
{
this._backgroundbrush = value;
}
}
}
上記のプロパティとそのカテゴリに次のコードでアクセスすると、元のカテゴリ「デフォルト」ではなくカテゴリとして「その他」が返されます。
public static void GetCategoryName()
{
PropertyInfo[] Props = typeof(Test).GetProperties(BindingFlags.Public | BindingFlags.Instance);
foreach (PropertyInfo prop in Props)
{
var attributes = prop.GetCustomAttributes(false);
string categoryName = String.Empty;
foreach (var attr in attributes)
{
if (attr is CategoryAttribute)
{
categoryName = (attr as CategoryAttribute).Category;
}
}
}
}
しかし、「デフォルト」以外のカテゴリ名を変更すると、正確なカテゴリ名が返されます。
私の質問は、「デフォルト」がカテゴリとして設定されているときに「その他」が返される理由です。
よろしく、
アマル・ラージ