Monday, December 17, 2007

CLS Attribute in DotNet

Hi Guys,

The when i see the microsoft forums and other forums sites, many guys ask about CLSCompliant attribute in the class file or assembly. i have idea about that , and i will post here. It's not complicated, but have some conditions and etc...

The conditions means, CLS-Command Language Specification(.NET).When i can say .net is great framework for all guys.because of it's multi language supporting such as VB.NET,C++.NET,C#.NET,J# and etc....Somebody can ask how can support a framework to multi language? answer is that is th .NET FRAMEWORK.

Come to point..
so when we try a code in any language with .net Framework, we must follow few rules , when we will apply
CLSCompliant attribute.

a::The methods are not same. it;s we have one method call "GetUsers()", and we don't have a method like "GETUSERS()".

b::Only properties and methods may be overloaded, Operators should not be overloaded.

c::We must avoid unsignned datatype within the class file

d::Publicly exposed members cannot start with an underscore ( _ )

e::Unsafe types like pointers should not be used with public members. However they can be used with private members.

f::Operators can't be overloaded

g::Unsigned types should not be part of the public interface of the class.


we can apply CLSCompliant to assemblies, modules, types, and members.

Example::A(apply to class)
[CLSCompliant(true)]
public class Smp
{

}

Example::B(apply to assembly
using System;
[assembly:CLSCompliant(true)]

Con....

If you develop applications that conform to the CLS, your program will be interoperable with a wide range of .Net supported programming languages. Therefore, your application is likely to have a wider customer base than a non-CLS-compliant version of your application. You can make sure that the C# programs you develop are CLS compliant by using the CLSCompliantAttribute, which will cause the compiler to raise errors if the program is not CLS compliant.

Best Regards
RRave
MCTS,MCPD

No comments: