Reflecting on Method Parameters and Return Values
So far, so good! Let’s make one minor enhancement to the current application. Specifically, you will
update the ListMethods() helper function to list not only the name of a given method, but also the
return value and incoming parameters. The MethodInfo type provides the ReturnType property and
GetParameters() method for these very tasks. In the following code, notice that you are building a
string type that contains the type and name of each parameter using a nested foreach loop:
static void ListMethods(Type t)
{
Console.WriteLine("***** Methods *****");
MethodInfo[] mi = t.GetMethods();
foreach (MethodInfo m in mi)
{
Do'stlaringiz bilan baham: |