C# program to print method names and its parameters using reflection classes

When we search for specific information, some articles do not find the information we need. But we hope you find the ideas you need in the C# program to print method names and its parameters using reflection classes article. Let’s go into the article.

C# program to print method names and its parameters using reflection classes

C# program to print method names and its parameters using reflection classes

//C# program to print method names and 
//its parameters using reflections.

using System;
using System.Reflection;

class Sample
{
    int num1;
    int num2;

    public void SetValues(int n1, int n2)
    {
        num1 = n1;
        num2 = n2;
    }

    public void PrintValues()
    {
        Console.WriteLine("Num1 :"+ num1);
        Console.WriteLine("Num2 :"+ num2);
    }

    static void Main(string[] args)
    {
        Assembly asm;
        Type[] types;

        asm = Assembly.GetExecutingAssembly();
        types = asm.GetTypes();

        foreach (Type cls in types)
        {
            MethodInfo[] methodNames = cls.GetMethods();
            foreach (MethodInfo method in methodNames)
            {
                Console.WriteLine(method.Name);

                ParameterInfo[] param = method.GetParameters();
                foreach (ParameterInfo p in param)
                {
                    Console.WriteLine("\t"+p.Name);
                }

            }
        }
    }
}
SetValues
        n1
        n2
PrintValues
ToString
Equals
        obj
GetHashCode
GetType
Press any key to continue . . .

Final Words

We hope you enjoy the article C# program to print method names and its parameters using reflection classes. The reason for that is that we hope that all your doubts and all doubts will be resolved through this article. Thanks

Hi, I'm Selva a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Deekshi. Here, I post about programming to help developers.

Share on:

Leave a Comment