Non-CLS-Compliant Types in C#

Question
How do I handle public members that work with non-CLS (Common Language Specification) object types?

Answer
You want to avoid public methods or properties that take or return types that aren’t CLS-compliant. For example, unsigned integers. However, if you can’t avoid these members, mark them with the CLSCompliant(false) attribute.

Comments
The compiler only honors the CLSCompliant attribute for public members in public types. Additionally, a type or member can’t be marked as CLS-compliant unless the assembly is also attributed as CLSCompliant(true).

Example

public class SimpleClass {
    [CLSCompliant(false)]
    public void DoWork(uint someNumber) {
        ...
    }
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s