how can find the list of method names of a class in c# [Resolved]

Posted by Bageshkumarbagi under C# on 8/3/2014 | Points: 10 | Views : 663 | Status : [Member] | Replies : 3
Hi ,
how can find the list of method names of a class and interface in c#. I means i have created some class and each class has some methods i want to get the list of all methods name of all class.For example class A has three method AM1(),AM2(),AM() and class B has 2 methods BM1(),BM2(). I want to get output as Class A having AM1(),AM2(),AM3() Class B having BM1(),BM2()
Methods. How can we get it.

Thanks in advance.

Thanks,
Bagesh Kumar Singh
Mark as answer if you have been satisfied



Responses

Posted by: Bandi on: 8/4/2014 [Member] [MVP] Platinum | Points: 50

Up
0
Down

Resolved
using System;
using System.Linq;

class Test
{
static void Main()
{
ShowMethods(typeof(DateTime));
}

static void ShowMethods(Type type)
{
foreach (var method in type.GetMethods())
{
var parameters = method.GetParameters();
var parameterDescriptions = string.Join
(", ", method.GetParameters()
.Select(x => x.ParameterType + " " + x.Name)
.ToArray());

Console.WriteLine("{0} {1} ({2})",
method.ReturnType,
method.Name,
parameterDescriptions);
}
}
}


OUTPUT:

System.DateTime Add (System.TimeSpan value)
System.DateTime AddDays (System.Double value)
System.DateTime AddHours (System.Double value)
System.DateTime AddMilliseconds (System.Double value)
System.DateTime AddMinutes (System.Double value)
System.DateTime AddMonths (System.Int32 months)
System.DateTime AddSeconds (System.Double value)
System.DateTime AddTicks (System.Int64 value)
System.DateTime AddYears (System.Int32 value)
System.Int32 Compare (System.DateTime t1, System.DateTime t2)
System.Int32 CompareTo (System.Object value)
System.Int32 CompareTo (System.DateTime value)
System.Int32 DaysInMonth (System.Int32 year, System.Int32 month)


Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Bageshkumarbagi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: vishalneeraj-24503 on: 8/3/2014 [Member] [MVP] Platinum | Points: 25
Posted by: Rasikbapotra on: 8/7/2014 [Member] Starter | Points: 25

Up
0
Down
private MethodInfo[] GetObjectMethods(string selectedObjClass)
{
MethodInfo[] methodInfos;
Assembly assembly = Assembly.GetAssembly(typeof(sampleAdapater));
Type _type = assembly.GetType("SampleSolution.Data.MyData." + selectedObjClass);

methodInfos = _type.GetMethods(BindingFlags.Public | BindingFlags.Static);

return methodInfos;

}

Bageshkumarbagi, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response