如何获取当前属性的PropertyDescriptor?
如何获取当前属性的 PropertyDescriptor
?例如:
[MyAttribute("SomeText")]
public string MyProperty
{
get{....}
set
{
// here I want to get PropertyDescriptor for this property.
}
}
How can I get the PropertyDescriptor
for the current property? For example:
[MyAttribute("SomeText")]
public string MyProperty
{
get{....}
set
{
// here I want to get PropertyDescriptor for this property.
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
你可以试试这个:
You could try this:
对于那些在这篇文章中寻找通用函数的人来说,这是一个可重用的转换函数:
这是一个扩展方法:
Here's a re-usable conversion function for those who got to this post looking for a general function:
and here's an extension method:
我发现以下方法有效:
其中
PropertyName
是传递到方法中的值。I found that the following worked:
where
PropertyName
is a value passed into a method.这个怎么样?
我认为您是在问是否可以在没有字符串的情况下执行此操作 - 即表示“此属性”的其他标记。我认为那不存在。但是,既然您无论如何都在编写这段代码(?),那么仅将属性名称放入代码中有何困难?
How about this?
I think you're asking if you can do this without the string - i.e. some other token that represents 'this property'. I don't think that exists. But since you are writing this code anyway (?) what is the difficulty in just putting the name of the property in the code?
为了将来参考,您现在可以执行以下操作:
For future reference, you can now do this: