how to get all classes with a specific method in current project RRS feed

  • Question

  • I have Project instance, in that project i need to find all files/ProjectItem (C# classes, 1 class in 1 file) which has method with a specific attribute.

    SO in current project i need to find all classes which have a MyCustomAttribute defined for any of their method.

    In dll, i can use reflection to do this; but how can i do when I have opened project in VS. Can i behind the scene compile project and then from DLL use reflection to get appropriate classes. Or i have to iterate over all items in current project and use fileCodeModel to see if attribute is implemented or not.



    Friday, September 30, 2011 1:41 PM


All replies

  • Using the filecodemodel or programatically parsing the files would probably be the easiest scenario to impelment.

    If you load the assembly into the VS IDE's main appdomain, you will wind up locking the assembly and be forced to restart the IDE before you can rebuild it. To avoid that you'd need to store off a copy of the assembly so as to not lock up the one in your ...\bin folder.



    Ed Dore
    Saturday, October 1, 2011 1:19 AM
  • See:

    HOWTO: Navigate the files of a solution from a Visual Studio .NET macro or add-in.

    HOWTO: Navigate the code elements of a file from a Visual Studio .NET macro or add-in.

    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 Saturday, October 1, 2011 7:42 AM
    • Marked as answer by singhhome Monday, October 3, 2011 4:59 PM
    Saturday, October 1, 2011 7:42 AM