MSMVPS.COM
The Ultimate Destination for Blogs by Current and Former Microsoft Most Valuable Professionals.

Using the CLSCompliant attribute

I'm out of the office this week doing some .NET mentoring at a client's site. This sort of work always ends up evolving MM .NET since I get a chance to see how developers are using it in building real-world applications. One of the new features in MM .NET that will come from this visit is pick lists for Windows Forms...stay tuned for more information!

Did you know...

You can apply the CLSCompliant attribute on an assembly (or just about any other program element) and have the compiler check if your code is CLS (Common Language System) compliant (which means it works properly when consumed by other .NET languages). For example, we place the following attribute in all MM .NET AssemblyInfo.cs files:

[assembly: CLSCompliant(true)]

Here are some of the things the compiler checks:

  • Class and member names cannot differ only by case. For example, you can't have one property named Counter and another named counter. This is important for cross-language compatibility since VB .NET isn't case sensitive.
  • Overloaded class methods cannot differ only by out or ref parameter designations.
  • Publicly exposed members cannot start with an underscore ( _ ).
  • Operators can't be overloaded
  • Unsigned types can't be part of the public interface of a class

Unfortunately, although you can apply the CLSCompliant attribute in VB .NET, the VB .NET compiler doesn't check for CLS compliance.

Kevin McNeish
Microsoft .NET/C# MVP


Posted Aug 18 2004, 06:10 PM by KevinMcNeish

Add a Comment

(required)  
(optional)
(required)  
Remember Me?


Copyright © is the original authors. Blog site is an independent site not sponsored by Microsoft. The Yoda blog server and the Brianna SQL server would like to thank www.ownwebnow.com and www.exchangedefender.com. They wouldn't be here and broadcasting without the generosity of Vlad Mazek and his companies.

Powered by Community Server (Commercial Edition), by Telligent Systems