
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
182
|
Chapter 3: Classes and Structures
CLS compliance is enforced only on types/members marked public or
protected. This makes sense because components written in other lan-
guages will be able to use only the public or protected types/members
of components written in C#.
Marking your assembly as CLS-compliant means that any CLS-compliant language
will be able to seamlessly interoperate with your code; that is, it enables CLS compli-
ance checking. This makes it much easier on developers to catch problems before
they manifest themselves, especially in an environment in which multiple managed
languages are being used on a single project. Marking your entire assembly to be
CLS-compliant is done with the following line of code:
[assembly: CLSCompliantAttribute(true)]
Sometimes you just can’t be 100 percent CLS compliant, but you don’t want to have
to throw away the benefit of compiler checking for the 99.9 percent of your methods
that are CLS compliant just so you can expose one method that is not. To mark these
types or members as not being CLS compliant, use the following attribute:
[CLSCompliantAttribute(false)]
By passing a value of false to this constructor’s isCompliant parameter, you prevent
any type/member marked as such from causing compiler errors due to non-CLS-
compliant code.