Share via


Interoperabilidade entre linguagens

Esta seção descreve o Common Language Runtimedo interno-no suporte para interoperabilidade de linguagem e explica a função que o Common Language Specification (CLS) desempenha em Ativar o garantida entre a interoperabilidade de linguagem-.

Interoperabilidade de linguagem é a capacidade de interagir com o código é escrito usando uma linguagem de programação diferente do código. Interoperabilidade de linguagem pode ajudar a maximizar o código reutilizar e melhorar a eficiência do processode desenvolvimento.

Because developers use a wide variety of tools and technologies, each of which might support different features and types, it has historically been difficult to ensure language interoperability. However, language compilers and tools that target the common language runtime benefit from the runtime's built-in support for language interoperability.

The common language runtime provides the necessary foundation for language interoperability by specifying and enforcing a common type system and by providing metadata. Because all languages targeting the runtime follow the common type system rules for defining and using types, the usage of types is consistent across languages. Metadata enables language interoperability by defining a uniform mechanism for storing and retrieving information about types. Compilers store type information as metadata, and the common language runtime uses this information to provide services during execution; the runtime can manage the execution of multilanguage applications because all type information is stored and retrieved in the same way, regardless of the language the code was written in.

Managed code benefits from the runtime's support for language interoperability in the following ways:

  • Types can inherit implementation from other types, pass objects to another type's methods, and call methods defined on other types, regardless of the language the types are implemented in.

  • Debuggers, profilers, or other tools are required to understand only one environment—the Microsoft intermediate language (MSIL) and metadata for the common language runtime—and they can support any programming language that targets the runtime.

  • Exception handling is consistent across languages. Your code can throw an exception in one language and that exception can be caught and understood by an object written in another language.

Even though the runtime provides all managed code with support for executing in a multilanguage environment, there is no guarantee that the functionality of the types you create can be fully used by the programming languages that other developers use. This is primarily because each language compiler targeting the runtime uses the type system and metadata to support its own unique set of language features. Em casos onde você não souber qual idioma o código de chamada será gravado, você provavelmente não sabe se os recursos de seu componente expõe são acessíveis ao chamador. Por exemplo, se o idioma de escolha fornece suporte para números inteiros sem sinal, você pode estruturar um método com um parâmetro do tipo UInt32. No entanto; Esse método seria inútil em uma linguagem que não tem noção de inteiros não assinados.

Para garantir que seu código gerenciado seja acessível para os desenvolvedores que usam outras linguagens de programação, o.NET Framework fornece a CLS (Common Language Specification) (CLS), que descreve um fundamentais de recursos de conjunto de idioma e define regras para como esses recursos são usados. For more information about CLS compliance in components and tools, see Gravando código compatível com CLS.

Title

Description

Common Language Specification

Explains the need for a set of features common to all languages and identifies CLS rules and features.

Writing CLS-Compliant Code

Discusses the meaning of CLS compliance for components and identifies levels of CLS compliance for tools.

Common Type System

Describes how types are declared, used, and managed by the common language runtime.

Metadata and Self-Describing Components

Explains the common language runtime's mechanism for describing a type and storing that information with the type itself.