C#,silverlight,检查 ref 传递的字段是否应用了属性
在基类中,我对派生类有以下方法:
protected virtual void SetValue<T>(ref T field, string propertyName, T value)
{
//assign value to the field and do some other staff
...
}
有什么方法可以检查 fieldVar 是否应用了属性(例如 DataMemberAttribute)?
In a base class I have the following method for derived classes:
protected virtual void SetValue<T>(ref T field, string propertyName, T value)
{
//assign value to the field and do some other staff
...
}
Is there any way to check if fieldVar has an attribute applied (for example DataMemberAttribute)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不,没有办法做到这一点,除了看起来你也被告知了属性名称。
如果你能找到字段的 FieldInfo,那么你就可以找到任何属性,但不能单独通过 ref 参数。
No, there is no way to do that, except that it looks like you're also told the property name.
If you can find the FieldInfo of the field, then you can find any attributes, but not through the ref-parameter alone.
从字里行间看,您有一组支持公共属性值的私有字段。在部分或全部这些属性上,您附加了一些您想要发现的数据属性。
Reading between the lines you have a set of private fields which back the values of public properties. On some or all of these properties you some data attributes attached that you want to discover.