1 / 18

METADATA IN .NET

METADATA IN .NET. Presented By Sukumar Manduva. INTRODUCTION. What is Metadata ? Metadata is a binary information which contains the complete description of every method, its parameters, its return type, the class in which the method exists including the assembly that

yama
Télécharger la présentation

METADATA IN .NET

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. METADATA IN .NET Presented By Sukumar Manduva

  2. INTRODUCTION • What is Metadata ? • Metadata is a binary information which contains the complete description of every method, its parameters, its return type, the class in which the method exists including the assembly that contains the class. • Metadata in .Net is analogous to .class files in Java

  3. What ? 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.

  4. Why ? • Why does .Net need metadata ? • With metadata .Net CLR postpones much of the work of the traditional linker until the program executes with some additional work at program load-time. • Metadata provides side-by-side execution and code access • security. • Metadata will be in common format irrespective of code written in different languages, This provides opportunity to code in language of users choice.

  5. Where ? • Where is metadata stored ? • When a program is compiled for the common language runtime, it is converted to a PE file. • Metadata is stored in one section of a .NET Framework portable executable (PE) file, while Microsoft intermediate language (MSIL) is stored in another section of the PE file. • The metadata portion of the file contains a series of table and heap data structures. • Each metadata table holds information about the elements of your program.

  6. Where ? When a program is compiled for the common language runtime, it is converted to a PE file that consists of three parts. The following table describes the contents of each part.

  7. Metadata Tokens • The MSIL portion contains MSIL and metadata tokens that reference the Metadata portion of the PE file • Each row of each metadata table is uniquely identified in the MSIL portion of the PE file by a metadata token • Metadata tokens are conceptually similar to pointers, persisted in MSIL, that reference a particular metadata table. • A metadata token is a four-byte number. The top byte denotes the metadata table to which a particular token refers (method, type, and so on) • The remaining three bytes specify the row in the metadata table that correspond to the programming element being described.

  8. A Simple example using System; using System.Collections.Generic; using System.Text; namespace Sukumar { class Program { static void Main(string[] args) { Console.WriteLine("HELLO SUKUMAR"); } } }

  9. The Assembly Manifest

  10. Intermediate Language of Constructor The IL code for constructor declares the stack, loads the arguments, calls the constructor for the base class System.Object (because all types are derived from System.Object) and returned from the constructor function.

  11. Intermediate Language for Main The IL code for Main declares it to be the entry point and loads the string "HELLO SUKUMAR“, calls System.Console::WriteLine() to write the string and returns the execution.

  12. Metadata Hierarchy

  13. Metadata and Reflection • What is Reflection and how it works? • Reflection is the ability to read metadata at runtime. • Using reflection, it is possible to uncover the methods, properties, and events of a type, and to invoke them dynamically. • Reflection also allows us to create new types at runtime. • Reflection generally begins with a call to a method present on every object in the • .NET framework: GetType.

  14. The GetType method is a member of the System.Object class, and the method returns an instance of System.Type. • System.Type is the primary gateway to metadata. System.Type is actually derived from another important class for reflection: the MemeberInfo class from the System.Reflection namespace. • MemberInfo is a base class for many other classes who describe the properties and methods of an object, including FieldInfo, MethodInfo, ConstructorInfo, ParameterInfo, and EventInfo among others.

  15. Metadata Hierarchy in Reflection

  16. Conclusion Metadata in .NET cannot be underestimated. Metadata allows us to write a component in C# and let another application use the metadata from Visual Basic .NET allowing reusability. The metadata description of a type allows the runtime to layout an object in memory, to enforce security and type safety, and ensure version compatibilities. Metadata also enhances processing speed considerably.

More Related