Skip to content
This repository was archived by the owner on Aug 9, 2025. It is now read-only.

Commit 7103af9

Browse files
committed
Merge pull request #17 from Dmitry-Me/reflectioninsteadofdynamicbinding
Use Reflection directly to access FileType, cleanup late binding code.
2 parents 6a84f1b + f870134 commit 7103af9

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

CPPCheckPlugin/CPPCheckPluginPackage.cs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,19 +115,27 @@ private void checkCurrentProject()
115115
foreach (dynamic o in activeProjects)
116116
{
117117
dynamic project = o.Object;
118-
Type projectType = project.GetType();
119-
if (!projectType.FullName.EndsWith("VCProjectShim"))
118+
Type projectObjectType = project.GetType();
119+
var projectInterface = projectObjectType.GetInterface("Microsoft.VisualStudio.VCProjectEngine.VCProject");
120+
if (projectInterface == null)
120121
{
121122
System.Windows.MessageBox.Show("Only C++ projects can be checked.");
122123
return;
123124
}
124125
foreach (dynamic file in project.Files)
125126
{
126127
// Only checking cpp files (performance)
127-
String fileExtension = (file.Extension as String).ToLower();
128-
if (fileExtension == ".cpp" || fileExtension == ".cxx" || fileExtension == ".c" || fileExtension == ".c++" || fileExtension == ".cc" || fileExtension == ".cp")
128+
Type fileObjectType = file.GetType();
129+
// Automatic property binding fails with VS2013 for some unknown reason, using Reflection directly instead.
130+
var vcFileInterface = fileObjectType.GetInterface("Microsoft.VisualStudio.VCProjectEngine.VCFile");
131+
var fileType = vcFileInterface.GetProperty("FileType").GetValue(file);
132+
Type fileTypeEnumType = fileType.GetType();
133+
var fileTypeEnumConstant = Enum.GetName(fileTypeEnumType, fileType);
134+
if (fileTypeEnumConstant == "eFileTypeCppCode")
129135
{
130-
if (!(file.Name.StartsWith("moc_") && file.Name.EndsWith(".cpp")) && !(file.Name.StartsWith("ui_") && file.Name.EndsWith(".h")) && !(file.Name.StartsWith("qrc_") && file.Name.EndsWith(".cpp"))) // Ignoring Qt MOC and UI files
136+
String fileName = file.Name;
137+
// Ignoring Qt MOC and UI files
138+
if (!(fileName.StartsWith("moc_") && fileName.EndsWith(".cpp")) && !(fileName.StartsWith("ui_") && fileName.EndsWith(".h")) && !(fileName.StartsWith("qrc_") && fileName.EndsWith(".cpp")))
131139
{
132140
SourceFile f = createSourceFile(file.FullPath, currentConfig, project);
133141
if (f != null)
@@ -178,7 +186,8 @@ SourceFile createSourceFile(string filePath, Configuration targetConfig, dynamic
178186
{
179187
// Project-specific includes
180188
Type toolType = tool.GetType();
181-
if (toolType.FullName.EndsWith("VCCLCompilerToolShim"))
189+
var compilerToolInterface = toolType.GetInterface("Microsoft.VisualStudio.VCProjectEngine.VCCLCompilerTool");
190+
if (compilerToolInterface != null)
182191
{
183192
String includes = tool.AdditionalIncludeDirectories;
184193
String definitions = tool.PreprocessorDefinitions;

0 commit comments

Comments
 (0)