SlideShare a Scribd company logo
1 of 8
www.siri-kt.blogspot.com
C# Tutorial
Part 15 :
Reflection
www.siri-kt.blogspot.com
• Reflection objects are used for obtaining type information at
runtime. The classes that give access to the metadata of a running
program are in theSystem.Reflection namespace.
• The System.Reflection namespace contains classes that allow you
to obtain information about the application and to dynamically add
types, values, and objects to the application.
• Reflection has the following applications:
• It allows view attribute information at runtime.
• It allows examining various types in an assembly and instantiate
these types.
• It allows late binding to methods and properties
• It allows creating new types at runtime and then performs some
tasks using those types.
• Viewing Metadata
• We have mentioned in the preceding chapter that using reflection
you can view the attribute information.
• The MemberInfo object of the System.Reflection class needs to
be initialized for discovering the attributes associated with a class.
• In C#, reflection is a process to get metadata of a type at runtime.
The System.Reflection namespace contains required classes for
reflection such as:
• Type
• MemberInfo
• ConstructorInfo
• MethodInfo
• FieldInfo
• PropertyInfo
• TypeInfo
• EventInfo
• Module
• Assembly
• AssemblyName
• Pointer etc.
• The System.Reflection.Emit namespace contains classes to emit
• C# Type class
• C# Type class represents type declarations for
class types, interface types, enumeration types,
array types, value types etc. It is found in System
namespace. It inherits
System.Reflection.MemberInfo class.
Property Description
Assembly Gets the Assembly for this type.
AssemblyQualifiedName Gets the Assembly qualified name for this type.
Attributes Gets the Attributes associated with the type.
BaseType Gets the base or parent type.
FullName Gets the fully qualified name of the type.
IsAbstract is used to check if the type is Abstract.
IsArray is used to check if the type is Array.
IsClass is used to check if the type is Class.
IsEnum is used to check if the type is Enum.
IsInterface is used to check if the type is Interface.
IsNested is used to check if the type is Nested.
IsPrimitive is used to check if the type is Primitive.
IsPointer is used to check if the type is Pointer.
IsNotPublic is used to check if the type is not Public.
IsPublic is used to check if the type is Public.
IsSealed is used to check if the type is Sealed.
IsSerializable is used to check if the type is Serializable.
MemberType is used to check if the type is Member type of Nested type.
Module Gets the module of the type.
Name Gets the name of the type.
Method Description
GetConstructors() Returns all the public constructors for the Type.
GetConstructors(BindingFlag
s)
Returns all the constructors for the Type with specified
BindingFlags.
GetFields() Returns all the public fields for the Type.
GetFields(BindingFlags) Returns all the public constructors for the Type with specified
BindingFlags.
GetMembers() Returns all the public members for the Type.
GetMembers(BindingFlags) Returns all the members for the Type with specified BindingFlags.
GetMethods() Returns all the public methods for the Type.
GetMethods(BindingFlags) Returns all the methods for the Type with specified BindingFlags.
GetProperties() Returns all the public properties for the Type.
GetProperties(BindingFlags) Returns all the properties for the Type with specified
BindingFlags.
GetType() Gets the current Type.
GetType(String) Gets the Type for the given name.
For more visit our website
www.siri-kt.blogspot.com
Thanks for
Watching

More Related Content

What's hot

Inner Classes
Inner ClassesInner Classes
Inner Classes
parag
 
คำถาม 5 ข้อ
คำถาม 5 ข้อคำถาม 5 ข้อ
คำถาม 5 ข้อ
Tavit Tangviriya
 

What's hot (20)

Access specifiers (Public Private Protected) C++
Access specifiers (Public Private  Protected) C++Access specifiers (Public Private  Protected) C++
Access specifiers (Public Private Protected) C++
 
C# classes objects
C#  classes objectsC#  classes objects
C# classes objects
 
C# Access modifiers
C# Access modifiersC# Access modifiers
C# Access modifiers
 
java tutorial 4
 java tutorial 4 java tutorial 4
java tutorial 4
 
Inner Classes
Inner ClassesInner Classes
Inner Classes
 
C# Basics
C# BasicsC# Basics
C# Basics
 
Master of Computer Application (MCA) – Semester 4 MC0078
Master of Computer Application (MCA) – Semester 4  MC0078Master of Computer Application (MCA) – Semester 4  MC0078
Master of Computer Application (MCA) – Semester 4 MC0078
 
Python: Singleton Pattern
Python: Singleton PatternPython: Singleton Pattern
Python: Singleton Pattern
 
OOPs difference faqs- 2
OOPs difference faqs- 2OOPs difference faqs- 2
OOPs difference faqs- 2
 
คำถาม 5 ข้อ
คำถาม 5 ข้อคำถาม 5 ข้อ
คำถาม 5 ข้อ
 
Javasession8
Javasession8Javasession8
Javasession8
 
Access modifiers
Access modifiersAccess modifiers
Access modifiers
 
Constructor
ConstructorConstructor
Constructor
 
ICOM4015 CIIC4010 Exam Review #1
ICOM4015 CIIC4010 Exam Review #1 ICOM4015 CIIC4010 Exam Review #1
ICOM4015 CIIC4010 Exam Review #1
 
encapsulation and abstraction
encapsulation and abstractionencapsulation and abstraction
encapsulation and abstraction
 
[OOP - Lec 06] Classes and Objects
[OOP - Lec 06] Classes and Objects[OOP - Lec 06] Classes and Objects
[OOP - Lec 06] Classes and Objects
 
Object as function argument , friend and static function by shahzad younas
Object as function argument , friend and static function by shahzad younasObject as function argument , friend and static function by shahzad younas
Object as function argument , friend and static function by shahzad younas
 
Interfaces in java
Interfaces in javaInterfaces in java
Interfaces in java
 
Chapter 9 java
Chapter 9 javaChapter 9 java
Chapter 9 java
 
object oriented programming using c++
 object oriented programming using c++ object oriented programming using c++
object oriented programming using c++
 

Similar to 15reflection in c#

Md02 - Getting Started part-2
Md02 - Getting Started part-2Md02 - Getting Started part-2
Md02 - Getting Started part-2
Rakesh Madugula
 
oops-123991513147-phpapp02.pdf
oops-123991513147-phpapp02.pdfoops-123991513147-phpapp02.pdf
oops-123991513147-phpapp02.pdf
ArpitaJana28
 
Object-oriented Analysis, Design & Programming
Object-oriented Analysis, Design & ProgrammingObject-oriented Analysis, Design & Programming
Object-oriented Analysis, Design & Programming
Allan Mangune
 

Similar to 15reflection in c# (20)

Reflection
ReflectionReflection
Reflection
 
Reflection in C#
Reflection in C#Reflection in C#
Reflection in C#
 
Reflection Slides by Zubair Dar
Reflection Slides by Zubair DarReflection Slides by Zubair Dar
Reflection Slides by Zubair Dar
 
Generic
GenericGeneric
Generic
 
Lecture 8 Library classes
Lecture 8 Library classesLecture 8 Library classes
Lecture 8 Library classes
 
VB.net&OOP.pptx
VB.net&OOP.pptxVB.net&OOP.pptx
VB.net&OOP.pptx
 
Practical type mining in Scala
Practical type mining in ScalaPractical type mining in Scala
Practical type mining in Scala
 
Object Oriented Programming In .Net
Object Oriented Programming In .NetObject Oriented Programming In .Net
Object Oriented Programming In .Net
 
Objects and Types C#
Objects and Types C#Objects and Types C#
Objects and Types C#
 
Object-oriented programming
Object-oriented programmingObject-oriented programming
Object-oriented programming
 
Oops
OopsOops
Oops
 
Reflection in C Sharp
Reflection in C SharpReflection in C Sharp
Reflection in C Sharp
 
Md02 - Getting Started part-2
Md02 - Getting Started part-2Md02 - Getting Started part-2
Md02 - Getting Started part-2
 
Typescript: Beginner to Advanced
Typescript: Beginner to AdvancedTypescript: Beginner to Advanced
Typescript: Beginner to Advanced
 
Reflecting On The Code Dom
Reflecting On The Code DomReflecting On The Code Dom
Reflecting On The Code Dom
 
oops-123991513147-phpapp02.pdf
oops-123991513147-phpapp02.pdfoops-123991513147-phpapp02.pdf
oops-123991513147-phpapp02.pdf
 
Using class and object java
Using class and object javaUsing class and object java
Using class and object java
 
11 Using classes and objects
11 Using classes and objects11 Using classes and objects
11 Using classes and objects
 
Object-oriented Analysis, Design & Programming
Object-oriented Analysis, Design & ProgrammingObject-oriented Analysis, Design & Programming
Object-oriented Analysis, Design & Programming
 
Unit3 part1-class
Unit3 part1-classUnit3 part1-class
Unit3 part1-class
 

More from Sireesh K (20)

Cn10
Cn10Cn10
Cn10
 
chanakya neeti
chanakya neetichanakya neeti
chanakya neeti
 
chanakya neeti
chanakya neetichanakya neeti
chanakya neeti
 
What is mvc
What is mvcWhat is mvc
What is mvc
 
31c
31c31c
31c
 
31cs
31cs31cs
31cs
 
45c
45c45c
45c
 
44c
44c44c
44c
 
43c
43c43c
43c
 
42c
42c42c
42c
 
41c
41c41c
41c
 
40c
40c40c
40c
 
39c
39c39c
39c
 
38c
38c38c
38c
 
37c
37c37c
37c
 
35c
35c35c
35c
 
34c
34c34c
34c
 
33c
33c33c
33c
 
30c
30c30c
30c
 
29c
29c29c
29c
 

Recently uploaded

The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 
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
 

Recently uploaded (20)

Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
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...
 
latest AZ-104 Exam Questions and Answers
latest AZ-104 Exam Questions and Answerslatest AZ-104 Exam Questions and Answers
latest AZ-104 Exam Questions and Answers
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Philosophy of china and it's charactistics
Philosophy of china and it's charactisticsPhilosophy of china and it's charactistics
Philosophy of china and it's charactistics
 

15reflection in c#

  • 2. C# Tutorial Part 15 : Reflection www.siri-kt.blogspot.com
  • 3. • Reflection objects are used for obtaining type information at runtime. The classes that give access to the metadata of a running program are in theSystem.Reflection namespace. • The System.Reflection namespace contains classes that allow you to obtain information about the application and to dynamically add types, values, and objects to the application. • Reflection has the following applications: • It allows view attribute information at runtime. • It allows examining various types in an assembly and instantiate these types. • It allows late binding to methods and properties • It allows creating new types at runtime and then performs some tasks using those types. • Viewing Metadata • We have mentioned in the preceding chapter that using reflection you can view the attribute information. • The MemberInfo object of the System.Reflection class needs to be initialized for discovering the attributes associated with a class.
  • 4. • In C#, reflection is a process to get metadata of a type at runtime. The System.Reflection namespace contains required classes for reflection such as: • Type • MemberInfo • ConstructorInfo • MethodInfo • FieldInfo • PropertyInfo • TypeInfo • EventInfo • Module • Assembly • AssemblyName • Pointer etc. • The System.Reflection.Emit namespace contains classes to emit
  • 5. • C# Type class • C# Type class represents type declarations for class types, interface types, enumeration types, array types, value types etc. It is found in System namespace. It inherits System.Reflection.MemberInfo class.
  • 6. Property Description Assembly Gets the Assembly for this type. AssemblyQualifiedName Gets the Assembly qualified name for this type. Attributes Gets the Attributes associated with the type. BaseType Gets the base or parent type. FullName Gets the fully qualified name of the type. IsAbstract is used to check if the type is Abstract. IsArray is used to check if the type is Array. IsClass is used to check if the type is Class. IsEnum is used to check if the type is Enum. IsInterface is used to check if the type is Interface. IsNested is used to check if the type is Nested. IsPrimitive is used to check if the type is Primitive. IsPointer is used to check if the type is Pointer. IsNotPublic is used to check if the type is not Public. IsPublic is used to check if the type is Public. IsSealed is used to check if the type is Sealed. IsSerializable is used to check if the type is Serializable. MemberType is used to check if the type is Member type of Nested type. Module Gets the module of the type. Name Gets the name of the type.
  • 7. Method Description GetConstructors() Returns all the public constructors for the Type. GetConstructors(BindingFlag s) Returns all the constructors for the Type with specified BindingFlags. GetFields() Returns all the public fields for the Type. GetFields(BindingFlags) Returns all the public constructors for the Type with specified BindingFlags. GetMembers() Returns all the public members for the Type. GetMembers(BindingFlags) Returns all the members for the Type with specified BindingFlags. GetMethods() Returns all the public methods for the Type. GetMethods(BindingFlags) Returns all the methods for the Type with specified BindingFlags. GetProperties() Returns all the public properties for the Type. GetProperties(BindingFlags) Returns all the properties for the Type with specified BindingFlags. GetType() Gets the current Type. GetType(String) Gets the Type for the given name.
  • 8. For more visit our website www.siri-kt.blogspot.com Thanks for Watching