This attribute indicates if an element is compliant with the Common language specification or not.
In order to be CLS-compliant, a producer tool must have an option that enables users to produce only CLS-compliant types. Tool vendors may also wish to have an option that enables users to consume only CLS-compliant types, but this is not required for CLS-compliance.
In addition, the runtime SDK will provide a tool that verifies CLS compliance of any compiled library or executable.
The goal of the compiler switch and SDK tool is to give developers some indication of when they use features that are not guaranteed to be supported in all NGWS runtime programming languages.
The CLSCompliantAttribute indicates what assemblies are CLS compliant and what Types and Type members are not CLS Compliant in a compliant assembly.
Note: The CLSCompliantAttribute may not be applied to any member of an Interface or any abstract member of a base type as this would make the classes un-extensible.
There are two ways this custom attribute can be used:
On Assemblies- When applied to an Assembly, this attribute marks an Assembly as being CLS compliant. Unless otherwise noted all types defined in this assembly are assumed to be CLS compliant. Without this attribute, an assembly is considered to be non compliant, all type defined with in it are also considered to be non-compliant.
On Types and Type Members- This attribute may be applied to Types, Methods, Properties, Fields, or Events. It calls out those members of a CLS Compliant Assembly that are not compliant. Any member of CLS Compliant assembly that is not compliant must have a compliant alternative. The CLS compliance checking tools ignore any member that has this attribute. That is, no warning is given for violation in this member. This attribute is inherited by base classes.
For example: compiling code such as:
public int SetValue (unsigned int value);
would generate a CLS compliance warning because the type of value is not in the CLS.
However, if the method was defined as:
[CLSComplaintAttribute (false)] public int SetValue (unsigned int value); public int SetValue (long value);
No compiler warnings/errors would be generated.
This checking gets slightly more complicate when the parameter type is non-primitive type. For example:
public int SetValue (FooType value);
We have to know something about the parameter type (FooType) to know if this method is CLS compliant. We assume that types used in public interfaces but not defined in this compiland are CLS compliant if and only if:
1. The type is defined in an assembly that is marked with the System.CLSCompliantAttribute (true)
The type is not marked with the custom attribute System.CLSCompliantAttribute(false).
See the Common Langauge specification for more details.
Object
Attribute
CLSCompliantAttribute
[Visual Basic] Public Class CLSCompliantAttribute Inherits Attribute [C#] public class CLSCompliantAttribute : Attribute [C++] public __gc class CLSCompliantAttribute : public Attribute [JScript] public class CLSCompliantAttribute extends Attribute
[To be supplied.]
Namespace: System
Assembly: mscorlib.dll