SlideShare una empresa de Scribd logo
1 de 21
REFLECTION
       Rohit Vipin Mathews
INTRODUCTION

 Reflection is the process of runtime type
  discovery.
 Reflection is a generic term that describes
  the ability to inspect and manipulate program
  elements at runtime.
 Using reflection services, we are able to
  programmatically obtain the same metadata
  information displayed by ildasm.exe.
REFLECTION ALLOWS YOU TO:

 Enumerate the members of a type
 Instantiate a new object

 Execute the members of an object

 Find out information about a type

 Find out information about an assembly

 Inspect the custom attributes applied to a
  type
 Create and compile a new assembly
SYSTEM.REFLECTION NAMESPACE
THE SYSTEM.TYPE CLASS

 The System.Type class defines a number of
  members that can be used to examine a
  type’s metadata, a great number of which
  return types from the System.Reflection
  namespace.
 Eg: Type.GetMethods() returns an array of
  MethodInfo types, Type.GetFields() returns
  an array of FieldInfo types.
MEMBERS OF SYSTEM.TYPE
   IsAbstract
   IsArray
   IsClass
   IsCOMObject
   IsEnum
   IsInterface
   IsPrimitive
   IsNestedPrivate
   IsNestedPublic
   IsSealed
   IsValueType

   These properties allow you to discover a number of basic traits
    about the Type you are referring to (e.g., if it is an abstract
    method, an array, a nested class, and so forth).
   GetConstructors()
   GetEvents()
   GetFields()
   GetInterfaces()
   GetMembers()
   GetMethods().
   GetNestedTypes()
   GetProperties()

   These methods allow you to obtain an array representing the
    items (interface, method, property, etc.) you are interested in.
    Each method returns a related array (e.g., GetFields() returns a
    FieldInfo array, GetMethods() returns a MethodInfo array, etc.).
    Each of these methods has a singular form
    (e.g., GetMethod(), GetProperty(), etc.) that allows you to retrieve
    a specific item by name, rather than an array of all related items.
   FindMembers()
       This method returns an array of MemberInfo
        types based on search criteria.
   GetType()
       This static method returns a Type instance given
        a string name.
   InvokeMember()
       This method allows late binding to a given item.
USING SYSTEM.TYPE.GETTYPE()

 To obtain type information, you may call the
  static GetType() member of the System.Type
  class and specify the fully qualified string
  name of the type to examine.
 Compile-time knowledge of the type to be
  extracted from metadata is not required.
   The Type.GetType() method has overloads to allow
    you to specify two Boolean parameters, one of
    which controls whether an exception should be
    thrown if the type cannot be found, and the other of
    which establishes the case sensitivity of the string.
   Obtaining type information using the static
    Type.GetType() method:
    Type t = Type.GetType("CarLibrary.SportsCar", false, true);
   Obtaining type information for a type within an
    external assembly:
    Type t = Type.GetType("CarLibrary.SportsCar, CarLibrary");
REFLECTING ON METHODS
   Type.GetMethods() returns an array of
    System.Reflection.MethodInfo types.

// Display method names of type.
public static void ListMethods(Type t)
{
   Console.WriteLine("Methods");
   MethodInfo[] mi = t.GetMethods();
   foreach(MethodInfo m in mi)
       Console.WriteLine("->{0}", m.Name);
   Console.WriteLine("");
}
REFLECTING ON FIELDS
   Type.GetFields() returns an array of
    System.Reflection.FieldInfo types.

// Display field names of type
public static void ListFields(Type t)
{
   Console.WriteLine("Fields");
   FieldInfo[] fi = t.GetFields();
   foreach(FieldInfo field in fi)
       Console.WriteLine("->{0}", field.Name);
   Console.WriteLine("");
}
REFLECTING ON PROPERTIES
   Type. GetProperties() returns an array of
    System.Reflection. PropertyInfo types.

// Display property names of type.
public static void ListProps(Type t)
{
   Console.WriteLine("***** Properties *****");
   PropertyInfo[] pi = t.GetProperties();
   foreach(PropertyInfo prop in pi)
       Console.WriteLine("->{0}", prop.Name);
   Console.WriteLine("");
}
REFLECTING ON IMPLEMENTED INTERFACES

 ListInterfaces() prints out the names of any
  interfaces supported on the incoming type.
 The call to GetInterfaces() returns an array of
  System.Types, as interfaces are indeed types.
public static void ListInterfaces(Type t)
{
  Console.WriteLine("***** Interfaces *****");
  Type[] ifaces = t.GetInterfaces();
  foreach(Type i in ifaces)
  Console.WriteLine("->{0}", i.Name);
}
DISPLAYING VARIOUS STATISTICS
   It indicates whether the type is generic, what
    the base class is, whether the type is
    sealed, etc.

public static void ListVariousStats(Type t)
{
  Console.WriteLine("***** Various Statistics *****");
  Console.WriteLine("Base class is: {0}", t.BaseType);
  Console.WriteLine("Is type abstract? {0}", t.IsAbstract);
  Console.WriteLine("Is type sealed? {0}", t.IsSealed);
  Console.WriteLine("Is type generic?
  {0}", t.IsGenericTypeDefinition);
  Console.WriteLine("Is type a class type? {0}", t.IsClass);
}
DYNAMICALLY LOADING ASSEMBLIES

 The act of loading external assemblies on
  demand is known as a dynamic load.
 System.Reflection defines a class Assembly.
  Which enables to dynamically load an
  assembly and discover properties about the
  assembly.
 Assembly type enables to dynamically load
  private or shared assemblies, as well as load
  an assembly located at an arbitrary location.
using System;
using System.Reflection;
using System.IO;
namespace ExternalAssemblyReflector
{
class Program
{
static void DisplayTypesInAsm(Assembly asm)
{
   Console.WriteLine("n Types in Assembly");
   Console.WriteLine("->{0}", asm.FullName);
   Type[] types = asm.GetTypes();
   foreach (Type t in types)
        Console.WriteLine("Type: {0}", t);
}
static void Main(string[] args)
{
    Console.WriteLine("External Assembly Viewer ");
    Assembly asm = null;
    Console.WriteLine("nEnter an assembly to evaluate");
    asmName = Console.ReadLine();
    try
    {
          asm = Assembly.LoadFrom(asmName);
          DisplayTypesInAsm(asm);
    }
    catch
    {
          Console.WriteLine("Sorry, can't find assembly.");
    }
}
}
}
LATE BINDING

 Late binding is a technique in which you are
  able to create an instance of a given type
  and invoke its members at runtime without
  having compile-time knowledge of its
  existence.
 It increases applications Extensibility.
SYSTEM.ACTIVATOR CLASS
   Activator.CreateInstance() method, which is used to create an instance
    of a type in late binding.

    Assembly a = null;
    try
    {
          a = Assembly.Load("CarLibrary");
    }
    catch(FileNotFoundException e)
    {
          Console.WriteLine(e.Message);
          Console.ReadLine();
          return;
    }
    Type miniVan = a.GetType("CarLibrary.MiniVan");
    object obj = Activator.CreateInstance(miniVan);
    MethodInfo mi = miniVan.GetMethod("TurboBoost");
    mi.Invoke(obj, null);      //mi.Invoke(obj, paramArray);
Reflection power pointpresentation ppt

Más contenido relacionado

La actualidad más candente

Command line arguments
Command line argumentsCommand line arguments
Command line argumentsAshok Raj
 
N-Queens Combinatorial Problem - Polyglot FP for Fun and Profit – Haskell and...
N-Queens Combinatorial Problem - Polyglot FP for Fun and Profit – Haskell and...N-Queens Combinatorial Problem - Polyglot FP for Fun and Profit – Haskell and...
N-Queens Combinatorial Problem - Polyglot FP for Fun and Profit – Haskell and...Philip Schwarz
 
Python: Multiple Inheritance
Python: Multiple InheritancePython: Multiple Inheritance
Python: Multiple InheritanceDamian T. Gordon
 
Object-oriented Programming-with C#
Object-oriented Programming-with C#Object-oriented Programming-with C#
Object-oriented Programming-with C#Doncho Minkov
 
Event handling
Event handlingEvent handling
Event handlingswapnac12
 
Function & procedure
Function & procedureFunction & procedure
Function & procedureatishupadhyay
 
JavaScript Functions
JavaScript Functions JavaScript Functions
JavaScript Functions Reem Alattas
 
Pf cs102 programming-8 [file handling] (1)
Pf cs102 programming-8 [file handling] (1)Pf cs102 programming-8 [file handling] (1)
Pf cs102 programming-8 [file handling] (1)Abdullah khawar
 
Collection Framework in java
Collection Framework in javaCollection Framework in java
Collection Framework in javaCPD INDIA
 
ITFT-Constants, variables and data types in java
ITFT-Constants, variables and data types in javaITFT-Constants, variables and data types in java
ITFT-Constants, variables and data types in javaAtul Sehdev
 
JavaScript: Variables and Functions
JavaScript: Variables and FunctionsJavaScript: Variables and Functions
JavaScript: Variables and FunctionsJussi Pohjolainen
 
Datatype in c++ unit 3 -topic 2
Datatype in c++ unit 3 -topic 2Datatype in c++ unit 3 -topic 2
Datatype in c++ unit 3 -topic 2MOHIT TOMAR
 

La actualidad más candente (20)

Command line arguments
Command line argumentsCommand line arguments
Command line arguments
 
N-Queens Combinatorial Problem - Polyglot FP for Fun and Profit – Haskell and...
N-Queens Combinatorial Problem - Polyglot FP for Fun and Profit – Haskell and...N-Queens Combinatorial Problem - Polyglot FP for Fun and Profit – Haskell and...
N-Queens Combinatorial Problem - Polyglot FP for Fun and Profit – Haskell and...
 
C# basics
 C# basics C# basics
C# basics
 
Classes objects in java
Classes objects in javaClasses objects in java
Classes objects in java
 
Python: Multiple Inheritance
Python: Multiple InheritancePython: Multiple Inheritance
Python: Multiple Inheritance
 
Object-oriented Programming-with C#
Object-oriented Programming-with C#Object-oriented Programming-with C#
Object-oriented Programming-with C#
 
Event handling
Event handlingEvent handling
Event handling
 
Event handling
Event handlingEvent handling
Event handling
 
jQuery for beginners
jQuery for beginnersjQuery for beginners
jQuery for beginners
 
Ajax
AjaxAjax
Ajax
 
Function & procedure
Function & procedureFunction & procedure
Function & procedure
 
JavaScript Functions
JavaScript Functions JavaScript Functions
JavaScript Functions
 
Getting Started with C++
Getting Started with C++Getting Started with C++
Getting Started with C++
 
Pf cs102 programming-8 [file handling] (1)
Pf cs102 programming-8 [file handling] (1)Pf cs102 programming-8 [file handling] (1)
Pf cs102 programming-8 [file handling] (1)
 
7.data types in c#
7.data types in c#7.data types in c#
7.data types in c#
 
Collection Framework in java
Collection Framework in javaCollection Framework in java
Collection Framework in java
 
ITFT-Constants, variables and data types in java
ITFT-Constants, variables and data types in javaITFT-Constants, variables and data types in java
ITFT-Constants, variables and data types in java
 
JavaScript: Variables and Functions
JavaScript: Variables and FunctionsJavaScript: Variables and Functions
JavaScript: Variables and Functions
 
Reflection in C#
Reflection in C#Reflection in C#
Reflection in C#
 
Datatype in c++ unit 3 -topic 2
Datatype in c++ unit 3 -topic 2Datatype in c++ unit 3 -topic 2
Datatype in c++ unit 3 -topic 2
 

Destacado

Attributes & .NET components
Attributes & .NET componentsAttributes & .NET components
Attributes & .NET componentsBình Trọng Án
 
.NET Attributes and Reflection - What a Developer Needs to Know...
.NET Attributes and Reflection - What a Developer Needs to Know....NET Attributes and Reflection - What a Developer Needs to Know...
.NET Attributes and Reflection - What a Developer Needs to Know...Dan Douglas
 
Bp sesmic interpretation
Bp sesmic interpretationBp sesmic interpretation
Bp sesmic interpretationMarwan Mahmoud
 
Basics of seismic interpretation
Basics of seismic interpretationBasics of seismic interpretation
Basics of seismic interpretationAmir I. Abdelaziz
 
Reflection power point
Reflection power pointReflection power point
Reflection power pointKatlinSapp
 
Reflective Practice Presentation
Reflective Practice PresentationReflective Practice Presentation
Reflective Practice PresentationJennifer Fenton
 
chapter 10 - refraction of light (na)
chapter 10 -  refraction of light (na)chapter 10 -  refraction of light (na)
chapter 10 - refraction of light (na)Stanley Ang
 
Session#1 csharp MTCS
Session#1 csharp MTCSSession#1 csharp MTCS
Session#1 csharp MTCSAhmad Ehab
 

Destacado (9)

Attributes & .NET components
Attributes & .NET componentsAttributes & .NET components
Attributes & .NET components
 
.NET Attributes and Reflection - What a Developer Needs to Know...
.NET Attributes and Reflection - What a Developer Needs to Know....NET Attributes and Reflection - What a Developer Needs to Know...
.NET Attributes and Reflection - What a Developer Needs to Know...
 
.NET Reflection
.NET Reflection.NET Reflection
.NET Reflection
 
Bp sesmic interpretation
Bp sesmic interpretationBp sesmic interpretation
Bp sesmic interpretation
 
Basics of seismic interpretation
Basics of seismic interpretationBasics of seismic interpretation
Basics of seismic interpretation
 
Reflection power point
Reflection power pointReflection power point
Reflection power point
 
Reflective Practice Presentation
Reflective Practice PresentationReflective Practice Presentation
Reflective Practice Presentation
 
chapter 10 - refraction of light (na)
chapter 10 -  refraction of light (na)chapter 10 -  refraction of light (na)
chapter 10 - refraction of light (na)
 
Session#1 csharp MTCS
Session#1 csharp MTCSSession#1 csharp MTCS
Session#1 csharp MTCS
 

Similar a Reflection power pointpresentation ppt

Reflecting On The Code Dom
Reflecting On The Code DomReflecting On The Code Dom
Reflecting On The Code DomNick Harrison
 
Reflection in C Sharp
Reflection in C SharpReflection in C Sharp
Reflection in C SharpHarman Bajwa
 
Creat Shape classes from scratch DETAILS You will create 3 shape cla.pdf
Creat Shape classes from scratch DETAILS You will create 3 shape cla.pdfCreat Shape classes from scratch DETAILS You will create 3 shape cla.pdf
Creat Shape classes from scratch DETAILS You will create 3 shape cla.pdfaromanets
 
08 class and object
08   class and object08   class and object
08 class and objectdhrubo kayal
 
03 oo with-c-sharp
03 oo with-c-sharp03 oo with-c-sharp
03 oo with-c-sharpNaved khan
 
5. c sharp language overview part ii
5. c sharp language overview   part ii5. c sharp language overview   part ii
5. c sharp language overview part iiSvetlin Nakov
 
15reflection in c#
15reflection  in c#15reflection  in c#
15reflection in c#Sireesh K
 
Java Sorting CodeImplementing and testing all three sort algorithm.pdf
Java Sorting CodeImplementing and testing all three sort algorithm.pdfJava Sorting CodeImplementing and testing all three sort algorithm.pdf
Java Sorting CodeImplementing and testing all three sort algorithm.pdfforecastfashions
 
Reflection Slides by Zubair Dar
Reflection Slides by Zubair DarReflection Slides by Zubair Dar
Reflection Slides by Zubair Darzubairdar6
 
Defining classes-and-objects-1.0
Defining classes-and-objects-1.0Defining classes-and-objects-1.0
Defining classes-and-objects-1.0BG Java EE Course
 
C# Language Overview Part II
C# Language Overview Part IIC# Language Overview Part II
C# Language Overview Part IIDoncho Minkov
 
Generic Types in Java (for ArtClub @ArtBrains Software)
Generic Types in Java (for ArtClub @ArtBrains Software)Generic Types in Java (for ArtClub @ArtBrains Software)
Generic Types in Java (for ArtClub @ArtBrains Software)Andrew Petryk
 

Similar a Reflection power pointpresentation ppt (20)

Reflection
ReflectionReflection
Reflection
 
Reflecting On The Code Dom
Reflecting On The Code DomReflecting On The Code Dom
Reflecting On The Code Dom
 
Reflection
ReflectionReflection
Reflection
 
Reflection in C Sharp
Reflection in C SharpReflection in C Sharp
Reflection in C Sharp
 
Creat Shape classes from scratch DETAILS You will create 3 shape cla.pdf
Creat Shape classes from scratch DETAILS You will create 3 shape cla.pdfCreat Shape classes from scratch DETAILS You will create 3 shape cla.pdf
Creat Shape classes from scratch DETAILS You will create 3 shape cla.pdf
 
Java 8 Lambda Expressions
Java 8 Lambda ExpressionsJava 8 Lambda Expressions
Java 8 Lambda Expressions
 
08 class and object
08   class and object08   class and object
08 class and object
 
Java Reflection
Java ReflectionJava Reflection
Java Reflection
 
03 oo with-c-sharp
03 oo with-c-sharp03 oo with-c-sharp
03 oo with-c-sharp
 
5. c sharp language overview part ii
5. c sharp language overview   part ii5. c sharp language overview   part ii
5. c sharp language overview part ii
 
C# overview part 2
C# overview part 2C# overview part 2
C# overview part 2
 
15reflection in c#
15reflection  in c#15reflection  in c#
15reflection in c#
 
Java Sorting CodeImplementing and testing all three sort algorithm.pdf
Java Sorting CodeImplementing and testing all three sort algorithm.pdfJava Sorting CodeImplementing and testing all three sort algorithm.pdf
Java Sorting CodeImplementing and testing all three sort algorithm.pdf
 
Java class
Java classJava class
Java class
 
Reflection Slides by Zubair Dar
Reflection Slides by Zubair DarReflection Slides by Zubair Dar
Reflection Slides by Zubair Dar
 
Defining classes-and-objects-1.0
Defining classes-and-objects-1.0Defining classes-and-objects-1.0
Defining classes-and-objects-1.0
 
C# Language Overview Part II
C# Language Overview Part IIC# Language Overview Part II
C# Language Overview Part II
 
Java interface
Java interfaceJava interface
Java interface
 
Generic Types in Java (for ArtClub @ArtBrains Software)
Generic Types in Java (for ArtClub @ArtBrains Software)Generic Types in Java (for ArtClub @ArtBrains Software)
Generic Types in Java (for ArtClub @ArtBrains Software)
 
Generics
GenericsGenerics
Generics
 

Último

Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxDr. Sarita Anand
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdfssuserdda66b
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxcallscotland1987
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseAnaAcapella
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 

Último (20)

Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 

Reflection power pointpresentation ppt

  • 1. REFLECTION Rohit Vipin Mathews
  • 2. INTRODUCTION  Reflection is the process of runtime type discovery.  Reflection is a generic term that describes the ability to inspect and manipulate program elements at runtime.  Using reflection services, we are able to programmatically obtain the same metadata information displayed by ildasm.exe.
  • 3. REFLECTION ALLOWS YOU TO:  Enumerate the members of a type  Instantiate a new object  Execute the members of an object  Find out information about a type  Find out information about an assembly  Inspect the custom attributes applied to a type  Create and compile a new assembly
  • 5. THE SYSTEM.TYPE CLASS  The System.Type class defines a number of members that can be used to examine a type’s metadata, a great number of which return types from the System.Reflection namespace.  Eg: Type.GetMethods() returns an array of MethodInfo types, Type.GetFields() returns an array of FieldInfo types.
  • 6. MEMBERS OF SYSTEM.TYPE  IsAbstract  IsArray  IsClass  IsCOMObject  IsEnum  IsInterface  IsPrimitive  IsNestedPrivate  IsNestedPublic  IsSealed  IsValueType  These properties allow you to discover a number of basic traits about the Type you are referring to (e.g., if it is an abstract method, an array, a nested class, and so forth).
  • 7. GetConstructors()  GetEvents()  GetFields()  GetInterfaces()  GetMembers()  GetMethods().  GetNestedTypes()  GetProperties()  These methods allow you to obtain an array representing the items (interface, method, property, etc.) you are interested in. Each method returns a related array (e.g., GetFields() returns a FieldInfo array, GetMethods() returns a MethodInfo array, etc.). Each of these methods has a singular form (e.g., GetMethod(), GetProperty(), etc.) that allows you to retrieve a specific item by name, rather than an array of all related items.
  • 8. FindMembers()  This method returns an array of MemberInfo types based on search criteria.  GetType()  This static method returns a Type instance given a string name.  InvokeMember()  This method allows late binding to a given item.
  • 9. USING SYSTEM.TYPE.GETTYPE()  To obtain type information, you may call the static GetType() member of the System.Type class and specify the fully qualified string name of the type to examine.  Compile-time knowledge of the type to be extracted from metadata is not required.
  • 10. The Type.GetType() method has overloads to allow you to specify two Boolean parameters, one of which controls whether an exception should be thrown if the type cannot be found, and the other of which establishes the case sensitivity of the string.  Obtaining type information using the static Type.GetType() method: Type t = Type.GetType("CarLibrary.SportsCar", false, true);  Obtaining type information for a type within an external assembly: Type t = Type.GetType("CarLibrary.SportsCar, CarLibrary");
  • 11. REFLECTING ON METHODS  Type.GetMethods() returns an array of System.Reflection.MethodInfo types. // Display method names of type. public static void ListMethods(Type t) { Console.WriteLine("Methods"); MethodInfo[] mi = t.GetMethods(); foreach(MethodInfo m in mi) Console.WriteLine("->{0}", m.Name); Console.WriteLine(""); }
  • 12. REFLECTING ON FIELDS  Type.GetFields() returns an array of System.Reflection.FieldInfo types. // Display field names of type public static void ListFields(Type t) { Console.WriteLine("Fields"); FieldInfo[] fi = t.GetFields(); foreach(FieldInfo field in fi) Console.WriteLine("->{0}", field.Name); Console.WriteLine(""); }
  • 13. REFLECTING ON PROPERTIES  Type. GetProperties() returns an array of System.Reflection. PropertyInfo types. // Display property names of type. public static void ListProps(Type t) { Console.WriteLine("***** Properties *****"); PropertyInfo[] pi = t.GetProperties(); foreach(PropertyInfo prop in pi) Console.WriteLine("->{0}", prop.Name); Console.WriteLine(""); }
  • 14. REFLECTING ON IMPLEMENTED INTERFACES  ListInterfaces() prints out the names of any interfaces supported on the incoming type.  The call to GetInterfaces() returns an array of System.Types, as interfaces are indeed types. public static void ListInterfaces(Type t) { Console.WriteLine("***** Interfaces *****"); Type[] ifaces = t.GetInterfaces(); foreach(Type i in ifaces) Console.WriteLine("->{0}", i.Name); }
  • 15. DISPLAYING VARIOUS STATISTICS  It indicates whether the type is generic, what the base class is, whether the type is sealed, etc. public static void ListVariousStats(Type t) { Console.WriteLine("***** Various Statistics *****"); Console.WriteLine("Base class is: {0}", t.BaseType); Console.WriteLine("Is type abstract? {0}", t.IsAbstract); Console.WriteLine("Is type sealed? {0}", t.IsSealed); Console.WriteLine("Is type generic? {0}", t.IsGenericTypeDefinition); Console.WriteLine("Is type a class type? {0}", t.IsClass); }
  • 16. DYNAMICALLY LOADING ASSEMBLIES  The act of loading external assemblies on demand is known as a dynamic load.  System.Reflection defines a class Assembly. Which enables to dynamically load an assembly and discover properties about the assembly.  Assembly type enables to dynamically load private or shared assemblies, as well as load an assembly located at an arbitrary location.
  • 17. using System; using System.Reflection; using System.IO; namespace ExternalAssemblyReflector { class Program { static void DisplayTypesInAsm(Assembly asm) { Console.WriteLine("n Types in Assembly"); Console.WriteLine("->{0}", asm.FullName); Type[] types = asm.GetTypes(); foreach (Type t in types) Console.WriteLine("Type: {0}", t); }
  • 18. static void Main(string[] args) { Console.WriteLine("External Assembly Viewer "); Assembly asm = null; Console.WriteLine("nEnter an assembly to evaluate"); asmName = Console.ReadLine(); try { asm = Assembly.LoadFrom(asmName); DisplayTypesInAsm(asm); } catch { Console.WriteLine("Sorry, can't find assembly."); } } } }
  • 19. LATE BINDING  Late binding is a technique in which you are able to create an instance of a given type and invoke its members at runtime without having compile-time knowledge of its existence.  It increases applications Extensibility.
  • 20. SYSTEM.ACTIVATOR CLASS  Activator.CreateInstance() method, which is used to create an instance of a type in late binding. Assembly a = null; try { a = Assembly.Load("CarLibrary"); } catch(FileNotFoundException e) { Console.WriteLine(e.Message); Console.ReadLine(); return; } Type miniVan = a.GetType("CarLibrary.MiniVan"); object obj = Activator.CreateInstance(miniVan); MethodInfo mi = miniVan.GetMethod("TurboBoost"); mi.Invoke(obj, null); //mi.Invoke(obj, paramArray);