locked
Get ProjectItems for Partial Class through CodeModel RRS feed

  • Question

  • Hello everyone,

    I have seen looking for a way to get the list of ProjectItems (files) for a known class, which generated from several partial classes. I use CodeModel to search for a class and accessing the ProjectItem to do stuff, which works fine for normal classes. But when it comes to partial classes, the ProjectItem property give one file but dont provide the other files which make this partial class.
    How can I access the other ProjectItems that make up the class , through partial classes

    Thanks,
    Chathuranga
    Saturday, January 30, 2010 7:53 AM

Answers

  • Hello,

    Given an EnvDTE.CodeClass, cast it to EnvDTE80.CodeClass2 and use the CodeClass2.Parts property to get the other (class) code element, whose ProjectItem property gives you the file of the partial class.
    MZ-Tools: Productivity add-ins for Visual Studio: http://www.mztools.com. My blog about developing add-ins: http://msmvps.com/blogs/carlosq/
    Monday, February 15, 2010 12:15 PM

All replies

  • Hello, Chathuranga

    As far as I know, there is no better way except enumerate all the projectItems.

     For the Code model, we mainly use two interfaces, FileCodeModel and CodeModel. FileCodeModel is just what you have tried.

    And for CodeModel, it is not well implemented in C# project type, so you couldn’t use it in C# project.  When you use CodeModel in VB.net, it just show all the codeElements, but it doesn’t merge the different partial classes from different projectItem into one class, it just show the partial classes with the same class name.

    Thanks

    Chao

    • Marked as answer by Chao Kuo Thursday, February 4, 2010 9:34 AM
    • Unmarked as answer by Chao Kuo Monday, March 1, 2010 2:43 AM
    Monday, February 1, 2010 8:49 AM
  • Hello,

    Given an EnvDTE.CodeClass, cast it to EnvDTE80.CodeClass2 and use the CodeClass2.Parts property to get the other (class) code element, whose ProjectItem property gives you the file of the partial class.
    MZ-Tools: Productivity add-ins for Visual Studio: http://www.mztools.com. My blog about developing add-ins: http://msmvps.com/blogs/carlosq/
    Monday, February 15, 2010 12:15 PM
  • Hi Carlos,

    Thank you very much for the the reply and this does solve the problem I had, reducing many loops.

    Regards,
    Chathuranga Wijeratna

    Saturday, February 27, 2010 5:45 PM
  • Great!! Thanks.
    Wednesday, March 16, 2011 12:07 AM