This article is a mirror article of machine translation, please click here to jump to the original article.

View: 40372|Reply: 0

[Source] .NET (CLS) public language specification

[Copy link]
Posted on 2021-1-11 11:43:49 | | | |
.NET is a separate language. This means that as a developer, you can develop in one of the many languages for .NET (e.g., C#, C++/CLI, Eiffel, F#, IronPython, IronRuby, PowerBuilder, Visual Basic, Visual COBOL, and Windows PowerShell). Access the types and members of libraries developed for .NET without having to know the language in which they were originally written or follow any conventions of the original language. If you're a component developer, your components can be accessed by any .NET app, regardless of the language.

If your component conforms to the common language specification, it is guaranteed that it is CLS compliant and accessible through code in an assembly written in any programming language that supports CLS. You can determine if your components comply with the common language specification at compile time by applying the CLSCompliantAttribute feature to the source code.

The Common Language Specification discusses each rule of CLS compliance because it applies to consumers (developers who programmatically access CLS-compliant components), frameworks (developers who use language compilers to create CLS-compliant libraries), and extensors (developers who create tools such as language compilers or code analyzers that create CLS-compliant components).
The program doesn't check if the code complies with CLS requirements by default when compiling, but if your program can be public (codeshare, Nuget release, etc.), it is recommended to use [assembly: CLSCompliant(true)]Indicate that your library is CLS compliant

Resources:

The hyperlink login is visible.
The hyperlink login is visible.
The hyperlink login is visible.

In layman's terms:

You can eat pilaf with your hands, you can eat with a spoon, there is no problem, however, eating with your hands does not meet hygienic standards or norms. CLS is a protocol specification, although the assembly will not report errors and will not affect normal use, but some types and parameters of the code you develop do not meet the standards.

Use CLS

In the AssemblyInfo.cs file, add the following code:



It will be applied to the entire assembly.

If you do not set this feature, you may receive the following error when adding this feature to an object:

Since assemblies do not have CLSCompliant features, "A.Test" does not require CLSCompliant features

The test code is as follows, then recompile:

The type of "A.Test" does not comply with CLS



You can see two warnings, click on the warning item to jump to the specific line number, indicating that our line of code does not comply with the CLS specification, and then you can correct it yourself.

If the line does not comply with the CLS specification, but the modification will affect the correct operation of the program, but you don't want VS to warn you, you can add the following characteristics to the field or class:



This way this warning will not be issued.

(End)





Previous:Entity Framework Query Optimization WITH(NOLOCK)
Next:.NET/C# to get the current application state (CPU, thread, GC)
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com