• Source
    1. using System;
    2. using System.Reflection;
    3.  
    4. public class Test
    5. {
    6. public void Method(int number, string text, bool isTrue = true)
    7. {
    8. string localVariable = "localVariable";
    9. if (localVariable != String.Empty)
    10. {
    11. Console.WriteLine();
    12. }
    13. }
    14.  
    15. public static void Main()
    16. {
    17. MethodInfo mInfo = typeof(Test).GetMethod("Method");
    18. Console.WriteLine("ParameterInfo");
    19. Console.WriteLine(
    20. "Pos | Name \t| Is In \t| IsOut \t| IsOptional \t|
    21. ParameterType \t| Member \t\t\t\t\t| RawDefaultValue"
    22. );
    23. foreach (ParameterInfo info in mInfo.GetParameters())
    24. {
    25. Console.WriteLine(
    26. "{0} \t | {1} \t| {2} \t| {3} \t| {4} \t| {5} \t| {6} \t| {7} "
    27. , info.Position, info.Name, info.IsIn, info.IsOut, info.IsOptional,
    28. info.ParameterType, info.Member, info.RawDefaultValue
    29. );
    30. }
    31. //Output:
    32. //ParameterInfo
    33. //Pos| Name | Is In | IsOut | IsOptional | ParameterType | Member | RawDefaultValue
    34. //0 | number | False | False | False | System.Int32 | Void Method(Int32, String, Boolean)|
    35. //1 | text | False | False | False | System.String | Void Method(Int32, String, Boolean)|
    36. //2 | isTrue | False | False | True | System.Boolean| Void Method(Int32, String, Boolean)| True
    37. }
    38. }