C# attribute usage: only allow attributes on a property with specific data type [duplicate]

送分小仙女□ 提交于 2019-11-29 14:15:46

You could write a custom FxCop/ Code Analysis rule to check for this.

FxCop is integrated in VS 2010 under the name "Code Analyis", you can change the ruleset in the project properties.

No, this is not possible.

A good workaround is to build a unit test which will traverse all classes, their properties and check for this additional applicability criteria. It's not that comfortable as a compile-time error message, but will serve the purpose. In case you have some kind of build automation infrastructure, the quality assurance level will be the same in practice.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!