将项目中的所有类标记为符合 CLS
如果我有一个项目,并将其标记为
<Assembly: CLSCompliant(True)>
是否需要将 CLSCompliant(True)
放在项目中的每个类之前,还是它们都默认为 CLSCompliant?
If I have a project and I mark it as
<Assembly: CLSCompliant(True)>
Do I need to put CLSCompliant(True)
before every class in the project, or are they all defaulted to CLSCompliant?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在程序集级别添加 CLSCompliant 属性无论如何都不会更改类,因此它不会使类符合 CLS。它的作用是强制编译器将任何不合规的内容作为错误引发。确保课程不违反规则仍然是您的责任。
尽管如此,是的,它确实会过滤并影响程序集中的所有类,而无需将其再次添加到每个类中。 从此处:
这篇文章也是一篇相当不错的文章很好地概述了它的工作原理、您需要做什么以及为什么您可能想要这样做。
Adding the CLSCompliant attribute at the assembly level does not change the classes in anyway, so it does not make the classes CLS compliant. What it does is to force the compiler to raise anything that isn't compliant as an error. It is still your responsibility to actually make sure the classes don't break the rules.
That said though, yes it does filter down and affect all the classes in the assembly without the need to add it again to each class. From here:
This article is also a quite a nice overview on how it works, what you need to do, and why you may want to do it.
我对 CLSCompliant 的了解是,默认情况下您的程序集不兼容。在我看来,并非所有项目都需要符合 CLSCompliant。将由其他应用程序使用的工具或库项目应该符合 CLS。在构建适用于 Windows Live 的 Visual Studion 工具时,我们必须确保我们的代码不会给出任何 CLSCompliant 错误或警告。
What I know about CLSCompliant is, by default your assembly is not compliant. In my opinion, not all projects need to be CLSCompliant. Projects which are tools or libraries, that are going to be used by other applications should be CLSCompliant. While building Visual Studion Tools for Windows Live, we had to make sure our code did not give any CLSCompliant errors or warnings.