【发布时间】:2010-11-21 12:42:48
【问题描述】:
我正在尝试从属性构造函数中确定与属性相关的属性的类型。更具体的我正在寻找包含该属性的类。
我当前的构造函数如下所示:
public IndexedCategoryAttribute(Type DefiningClass, String HeaderText, int Index)
{
this._definingClass = DefiningClass;
但我希望它看起来像:
public IndexedCategoryAttribute(String HeaderText, int Index)
{
PropertyInfo Info = ???
this._definingClass = Info.DeclaringType;
我相信这将为属性的用户提供更安全的代码,因为目前它在属性定义中需要一个“typeof(MyClass)”,这会导致提供错误类型的可能性?
有关更多信息,我将其与 propertygrid 一起使用。该类型在static Dictionary<Type, Dictionary<String, int>> 中用于将类别分组到与其相关的类。
【问题讨论】:
-
需要考虑的事项 - Microsoft 已经使用 Xceed 的 DataGrid for Visual Studio 2010 本身。
-
这与问题有什么关系?
标签: c# reflection properties attributes