• Source
    1. using System;
    2. using System.Reflection;
    3.  
    4. public class Test
    5. {
    6. public static void Main()
    7. {
    8. Console.WriteLine("LocalVariableInfo");
    9. MethodInfo mInfo = typeof(Test).GetMethod("Method");
    10. MethodBody mb = mInfo.GetMethodBody();
    11. foreach (LocalVariableInfo info in mb.LocalVariables)
    12. Console.WriteLine("Index: {2}, Local type: {0}, IsPinned: {1}, ", info.LocalType, info.IsPinned, info.LocalIndex);
    13. // Output:
    14. // LocalVariableInfo
    15. // Index: 0, Local type: System.String, IsPinned: False,
    16.  
    17. }
    18.  
    19. public void Method()
    20. {
    21. string localVariable = "localVariable";
    22. if (localVariable != String.Empty)
    23. {
    24. Console.WriteLine();
    25. }
    26. }
    27. }