Compartilhar via


Metadados e componentes autodescritivos

No passado, um software componente (. exe ou. dll) que foi gravado em um idioma não podia facilmente usar um componente de software que foi escrito em outro idioma. COM foi um passo em direção à solução desse problema. The .NET Framework makes component interoperation even easier by allowing compilers to emit additional declarative information into all modules and assemblies. Essa informação, chamada de metadados, ajuda os componentes a interagir perfeitamente.

Metadata is binary information describing your program that is stored either in a common language runtime portable executable (PE) file or in memory. Quando você compilar seu código em um arquivo PE, metadados é inserido em uma parte do arquivo e seu código é convertida para o Microsoft Intermediate Language (MSIL) e inserida em outra parte do arquivo. Cada tipo e membro definido e referenciado em um módulo ou assembly é descrito em metadados. When code is executed, the runtime loads metadata into memory and references it to discover information about your code's classes, members, inheritance, and so on.

Metadata describes every type and member defined in your code in a language-neutral manner. Metadata stores the following information:

  • Description of the assembly.

    • Identity (name, version, culture, public key).

    • The types that are exported.

    • Other assemblies that this assembly depends on.

    • Security permissions needed to run.

  • Description of types.

    • Name, visibility, base class, and interfaces implemented.

    • Members (methods, fields, properties, events, nested types).

  • Attributes.

    • Additional descriptive elements that modify types and members.

Benefits of Metadata

Metadados é a chave para um modelo de programação mais simples e elimina a necessidade de Interface Definição Language (IDL) arquivos, arquivos de cabeçalho ou qualquer método externo de referência do componente . Metadados permitem.NET Framework de linguagens se descrevam automaticamente de-de idioma neutro maneira, Vista pelo desenvolvedor e o usuário. Additionally, metadata is extensible through the use of attributes. Metadata provides the following major benefits:

  • Self-describing files.

    Common language runtime modules and assemblies are self-describing. A module's metadata contains everything needed to interact with another module. Os metadados fornecem automaticamente a funcionalidade de IDL COM, assim você pode usar um arquivo de definição e implementação. Runtime modules and assemblies do not even require registration with the operating system. As a result, the descriptions used by the runtime always reflect the actual code in your compiled file, which increases application reliability.

  • Language interoperability and easier component-based design.

    Metadata provides all the information required about compiled code for you to inherit a class from a PE file written in a different language. You can create an instance of any class written in any managed language (any language that targets the common language runtime) without worrying about explicit marshaling or using custom interoperability code.

  • Attributes.

    A.NET Framework permite que você declare tipos específicos de metadados, chamados atributos, no seu arquivo compilado. Attributes can be found throughout the .NET Framework and are used to control in more detail how your program behaves at run time. Additionally, you can emit your own custom metadata into .NET Framework files through user-defined custom attributes. For more information, see Estendendo metadados usando atributos.

Title

Description

Metadados e a estrutura de arquivos PE

Describes how metadata is stored separately from Microsoft intermediate language (MSIL) in a PE file.

Uso de metadados em tempo de execução

Demonstrates the use of metadata at run time with a code example.

Estendendo metadados usando atributos

Descreve como aplicar atributos, escrever atributos personalizados e recuperar as informações armazenadas em atributos.