views:

146

answers:

2

Hi

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?

+3  A: 

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.

Martin Harris
Thank's that's what I was hoping for. They're "only" internal tools I'm creating, but they will be used in various places (mostly by me) so I thought it makes sense to make them as reusable as possible.
Cylindric
A: 

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.

theraneman