using System;
using System.Reflection;
public class Test
{
public void Method(int number, string text, bool isTrue = true)
{
string localVariable = "localVariable";
if (localVariable != String.Empty)
{
Console.WriteLine();
}
}
public static void Main()
{
MethodInfo mInfo = typeof(Test).GetMethod("Method");
Console.WriteLine("ParameterInfo");
Console.WriteLine(
"Pos | Name \t| Is In \t| IsOut \t| IsOptional \t|
ParameterType \t| Member \t\t\t\t\t| RawDefaultValue"
);
foreach (ParameterInfo info in mInfo.GetParameters())
{
Console.WriteLine(
"{0} \t | {1} \t| {2} \t| {3} \t| {4} \t| {5} \t| {6} \t| {7} "
, info.Position, info.Name, info.IsIn, info.IsOut, info.IsOptional,
info.ParameterType, info.Member, info.RawDefaultValue
);
}
//Output:
//ParameterInfo
//Pos| Name | Is In | IsOut | IsOptional | ParameterType | Member | RawDefaultValue
//0 | number | False | False | False | System.Int32 | Void Method(Int32, String, Boolean)|
//1 | text | False | False | False | System.String | Void Method(Int32, String, Boolean)|
//2 | isTrue | False | False | True | System.Boolean| Void Method(Int32, String, Boolean)| True
}
}