- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to display methods and properties using reflection in C#?
Reflection is the process of describing the metadata of types, methods and fields in a code. The namespace System.Reflection enables you to obtain data about the loaded assemblies, the elements within them like classes, methods and value types. There are numerous classes of System.Reflection but the most commonly used ones are Assembly, AssemblyName, ConstructorInfo, MethodInfo, ParameterInfo, EventInfo, PropertyInfo, and MemberInfo.
Example
static void Main(string[] args){ TypeInfo myType = typeof(TextInfo).GetTypeInfo(); IEnumerable<PropertyInfo> properties = myType.DeclaredProperties; IEnumerable<MethodInfo> methods = myType.DeclaredMethods; Console.WriteLine(myType); Console.WriteLine(properties); Console.WriteLine(methods); StringBuilder strBuilder = new StringBuilder(); Console.WriteLine(); strBuilder.Append("The properties are:"); foreach (PropertyInfo p in properties){ strBuilder.Append("
" + p.Name); } strBuilder.Append("
"); strBuilder.Append("
The methods are:"); foreach (MethodInfo m in methods){ strBuilder.Append("
" + m.Name); } Console.WriteLine(strBuilder); }
Output
System.Globalization.TextInfo System.Reflection.PropertyInfo[] System.Reflection.MethodInfo[] The properties are: Invariant ANSICodePage OEMCodePage MacCodePage EBCDICCodePage LCID CultureName IsReadOnly ListSeparator IsAsciiCasingSameAsInvariant IsRightToLeft The methods are: get_Invariant get_ANSICodePage get_OEMCodePage get_MacCodePage get_EBCDICCodePage get_LCID get_CultureName get_IsReadOnly get_ListSeparator set_ListSeparator get_IsAsciiCasingSameAsInvariant get_IsRightToLeft System.Runtime.Serialization.IDeserializationCallback.OnDeserialization Clone ReadOnly VerifyWritable SetReadOnlyState ToLower ToLower ChangeCase ChangeCaseToLower ChangeCaseToUpper ChangeCaseCommon ChangeCaseCommon ChangeCaseCommon ToLowerAsciiInvariant ToLowerAsciiInvariant ToUpperAsciiInvariant ToUpperAsciiInvariant ToLowerAsciiInvariant ToUpper ToUpper ToUpperAsciiInvariant IsAscii PopulateIsAsciiCasingSameAsInvariant Equals GetHashCode ToString ToTitleCase AddNonLetter AddTitlecaseLetter IsWordSeparator IsLetterCategory FinishInitialization ChangeCase IsInvariantLocale
- Related Articles
- Call methods of an object using reflection in Java
- List methods of a class using Java Reflection
- How to add properties and methods to an object in JavaScript?
- How are the methods and properties of Array class in C# useful?
- How to add properties and methods to an existing object in JavaScript?
- PHP Static Properties and Methods
- Use reflection to create, fill, and display an array in Java
- How to get all properties and methods available for the service in PowerShell?
- What are the methods and properties of the Thread class in C#?
- How to display specific properties from Get-Service output in PowerShell?
- Using reflection to check array type and length in Java
- Reflection in C#
- C++ Program to Store and Display Information Using Structure
- How to define methods in C#?
- How to set a property having different datatype with a string value using reflection in C#?

Advertisements