Presentation is loading. Please wait.

Presentation is loading. Please wait.

METADATA IN.NET Presented By Sukumar Manduva. INTRODUCTION  What is Metadata ? Metadata is a binary information which contains the complete description.

Similar presentations


Presentation on theme: "METADATA IN.NET Presented By Sukumar Manduva. INTRODUCTION  What is Metadata ? Metadata is a binary information which contains the complete description."— 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  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. Metadata stores the following information: What?

4  Why does.Net need metadata ? Why? 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 ? PE SectionContents of PE section PE header The index of the PE file's main sections and the address of the entry point. The runtime uses this information to identify the file as a PE file and to determine where execution starts when loading the program into memory. MSIL instructions The Microsoft intermediate language instructions (MSIL) that make up your code. Many MSIL instructions are accompanied by metadata tokens. Metadata Metadata tables and heaps. The runtime uses this section to record information about every type and member in your code. This section also includes custom attributes and security information. 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 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. Metadata Tokens

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

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 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.  What is Reflection and how it works?

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.

17

18


Download ppt "METADATA IN.NET Presented By Sukumar Manduva. INTRODUCTION  What is Metadata ? Metadata is a binary information which contains the complete description."

Similar presentations


Ads by Google