VCCodeElements::Find Method (String^)
Visual Studio 2015
Returns the specified code element of the parent object.
Assembly: Microsoft.VisualStudio.VCCodeModel (in Microsoft.VisualStudio.VCCodeModel.dll)
Parameters
- bstrSearch
-
Type:
System::String^
Required. The name of the code element to search for. The string must be enclosed in double quotes.
If the specified code element was not found, the method returns null.
See How to: Compile Example Code for Visual C++ Code Model Extensibility for information on how to compile and run this sample.
This example looks for the THIS_FILE variable in the 'stdafx.h' file. If the variable is not found, it is added.
' Macro code. Sub AddThisFile() Try Dim vcCM As VCFileCodeModel Dim vcCodeElements As VCCodeElements vcCM = CType(DTE.Solution.Item(1). _ ProjectItems.Item("stdafx.h"), VCFileCodeModel) vcCodeElements = vcCM.CodeElements If (vcCodeElements.Find("THIS_FILE") Is Nothing) Then Dim codeVariable As VCCodeVariable codeVariable = vcCM.AddVariable("THIS_FILE", "char") End If catch e as System.Exception MsgBox(e.Message + e.StackTrace) End Try End Sub
Show: