How do you interact with using statements in VS2010 using the FileCodeModel
-
29-09-2019 - |
Question
I'm trying to build a Visual Studio 2010 vsix add on to alter (to start with just add and delete) using statements in a c# document. Using the FileCodeModel on the current ProjectItem I can see how to add classes, structs etc, but not using directives. Can anyone advise me on this?
Solution
Check FileCodeModel2 at http://msdn.microsoft.com/enus/library/envdte80.filecodemodel2.addimport(VS.80).aspx
OTHER TIPS
I've solved the problem. I can recursively analyze for CodeImports on the FileCodeModel which gives me a list of the current using directives. Unfortunately I can't find any AddCodeImport method in FileCodeModel and so presume it doesn't exist. As a result when I'm inserting using directives I've had to perform get the TextPoints associated with the last CodeImport (within the current namespace scope) and insert the using directive as text there.
This works fine, but I don't quite understand why there is no AddCodeImport method.