To Achieve Reflection we have to use System.Reflection namespace contains classes and interfaces that provide a managed view of loaded types, methods, and fields, with the ability to dynamically create and invoke types.
Here are the few Methods we have uses to investigate a user Object.
- GetMethods()
- GetProperties()
- GetConstructors()
Example:
class Program {
static void Main(string[] args) {
Console.WriteLine("Enter the Library Type :");
Type T = Type.GetType(Console.ReadLine());
MethodInfo[] med = T.GetMethods();
Console.WriteLine("************List Of Methods*****************");
Console.BackgroundColor = ConsoleColor.Blue;
foreach(var item in med) {
Console.WriteLine(item);
}
Console.BackgroundColor = ConsoleColor.Black;
Console.WriteLine("************List Of Properties*****************");
Console.BackgroundColor = ConsoleColor.Yellow;
PropertyInfo[] prop = T.GetProperties();
foreach(var item in prop) {
Console.WriteLine(item);
}
Console.BackgroundColor = ConsoleColor.Black;
Console.WriteLine("************List Of Constructor*****************");
Console.BackgroundColor = ConsoleColor.Green;
Console.ForegroundColor = ConsoleColor.Black;
ConstructorInfo[] ctr = T.GetConstructors();
foreach(var item in ctr) {
Console.WriteLine(item);
}
Console.BackgroundColor = ConsoleColor.Black;
Console.ReadLine();
}
}