基于属性的编程有哪些优点?
我正在使用 WCF RIA 服务,并且遇到了一个使用属性的示例:
[StringLength(10, ErrorMessage="Too long")]
public string FirstName { get; set; }
...
虽然属性不限于 WCF RIA,但它让我想起了一个问题:为什么声明性或基于属性的编程比编写验证例程“老式”更合适?方式” ?
谢谢,
斯科特
I am working with WCF RIA services and have come across a sample using attributes:
[StringLength(10, ErrorMessage="Too long")]
public string FirstName { get; set; }
...
While attributes aren't restricted to WCF RIA, it reminded me of a question: why is declarative or attribute based programming perferable to coding a validation routine "the old fashioned way" ?
Thanks,
Scott
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

发布评论
评论(4)
~没有更多了~
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
因为无需执行代码即可发现约束。通过反思,您可以访问这些约束。
Because the constraint is discoverable without having to execute the code. With reflection you can access these constraints.