locked
How can i access the code elements inside a function definition in visual studio add-in. RRS feed

  • Question

  • I am creating a visual studio plugin to analyze code. I am using EnvDTE namespace to access project and other project items.

    I want to list variables defined/used inside a function. I googled for that but didn't find any solution. So is there any way that i can access code inside a function.

    • Edited by RK Engineer Tuesday, February 12, 2013 11:58 AM correction
    Tuesday, February 12, 2013 9:16 AM

Answers

  • Hi

    The automation model (EnvDTE) doesn't provide a way to parse code elements inside a method, and there are no plans to enhance it.

    The Microsoft "Rosyln" project will provide rich code analysis: http://msdn.microsoft.com/en-us/vstudio/roslyn.aspx


    MZ-Tools: Productivity add-ins for Visual Studio: http://www.mztools.com. My blog about developing add-ins: http://msmvps.com/blogs/carlosq/

    • Proposed as answer by Carlos J. Quintero Wednesday, February 13, 2013 8:59 AM
    • Marked as answer by Ego Jiang Tuesday, February 26, 2013 8:53 AM
    Tuesday, February 12, 2013 2:09 PM
  • Reflection provides MethodBase.GetMethodBody, but question is the needs of the feature of your extension. Is it a feature intended for source code of a project/document or for the compiled code of the project (output build)?

    Reflection is only for compiled code, so:

    1) Maybe a project has not been compiled yet for the first time, so you wouldn't have any output build.

    2) Maybe the compiled code is out of date (the source code has changed since the last build)


    MZ-Tools: Productivity add-ins for Visual Studio: http://www.mztools.com. My blog about developing add-ins: http://msmvps.com/blogs/carlosq/



    Thursday, February 14, 2013 7:00 AM

All replies

  • Hi

    The automation model (EnvDTE) doesn't provide a way to parse code elements inside a method, and there are no plans to enhance it.

    The Microsoft "Rosyln" project will provide rich code analysis: http://msdn.microsoft.com/en-us/vstudio/roslyn.aspx


    MZ-Tools: Productivity add-ins for Visual Studio: http://www.mztools.com. My blog about developing add-ins: http://msmvps.com/blogs/carlosq/

    • Proposed as answer by Carlos J. Quintero Wednesday, February 13, 2013 8:59 AM
    • Marked as answer by Ego Jiang Tuesday, February 26, 2013 8:53 AM
    Tuesday, February 12, 2013 2:09 PM
  • Is there any other way to access code inside a function. Can we do this using System.Reflection?
    Thursday, February 14, 2013 5:02 AM
  • Reflection provides MethodBase.GetMethodBody, but question is the needs of the feature of your extension. Is it a feature intended for source code of a project/document or for the compiled code of the project (output build)?

    Reflection is only for compiled code, so:

    1) Maybe a project has not been compiled yet for the first time, so you wouldn't have any output build.

    2) Maybe the compiled code is out of date (the source code has changed since the last build)


    MZ-Tools: Productivity add-ins for Visual Studio: http://www.mztools.com. My blog about developing add-ins: http://msmvps.com/blogs/carlosq/



    Thursday, February 14, 2013 7:00 AM