开发者

Marking all classes in a project CLS Compliant

If I have a project and I mark it as

<Assembly: CLSCompliant(True)> 

Do I开发者_JAVA百科 need to put CLSCompliant(True) before every class in the project, or are they all defaulted to CLSCompliant?


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:

If no CLS attribute is applied to a type, that type is assumed to have the same CLS compliance as the assembly in which the type is defined.

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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜