- using System;
- using System.Reflection;
- namespace Reflection
- {
- class Coordinate
- {
- int x, y;
- public Coordinate(int x, int y)
- {
- this.x = x;
- this.y = y;
- }
- public void Position(string msg)
- {
- Console.WriteLine("{0} : {1},{2}", msg, x, y);
- }
- }
- class Program
- {
- static void Main()
- {
- Type typeObject = typeof (Coordinate);
- MethodInfo[] methods = typeObject.GetMethods();
- Console.Write("Methods Exists in Current Program:");
- foreach(MethodInfo method in methods)
- {
- Console.WriteLine("\nMethod Name: {0}", method.Name);
- ParameterInfo[] parameters = method.GetParameters();
- Console.WriteLine("Parameters Exists in {0}:", method.Name);
- foreach(ParameterInfo parameter in parameters)
- Console.WriteLine("\tName: {0}\n\tType: {1}", parameter.Name, parameter.ParameterType);
- }
- }
- }
- }
Ans:
Methods Exists in Current Program:
Method Name: Position Parameters Exists in Position:
Name: msg
Type: System.String