共用方式為


VCFileCodeModel.AddMacro(String, String, Object) Method

Definition

Adds a #define element to the VCFileCodeModel object.

Microsoft::VisualStudio::VCCodeModel::VCCodeMacro AddMacro(std::wstring const & Name, std::wstring const & Value = "", winrt::Windows::Foundation::IInspectable const & Position);
[System.Runtime.InteropServices.DispId(563)]
public Microsoft.VisualStudio.VCCodeModel.VCCodeMacro AddMacro (string Name, string Value = "", object Position);
[<System.Runtime.InteropServices.DispId(563)>]
abstract member AddMacro : string * string * obj -> Microsoft.VisualStudio.VCCodeModel.VCCodeMacro
Public Function AddMacro (Name As String, Optional Value As String = "", Optional Position As Object) As VCCodeMacro

Parameters

Name
String

Required. Specifies the name (in quotes or angle brackets) of the file being included.

Value
String

Optional. The text of the macro's definition.

Position
Object

Required. Default = 0. The code element after which to add the new element. If the value is a CodeElement, then the new element is added immediately after it.Because collections begin their count at one, passing 0 indicates that the new element should be placed at the beginning of the collection. A value of -1 means the element should be placed at the end.

Returns

A VCCodeMacro object.

Attributes

Examples

This example adds a macro statement to the file represented by the vcFile object.

Sub AddMacro()  
    Dim vcFile as VCFileCodeModel  
    vcFile = DTE.Solution.Item(1).ProjectItems.Item(1).FileCodeModel  
    vcFile.AddMacro("LAST_CHAR", "'Z'", 0)  
End Sub  

Remarks

Call this function to insert a #define Directive (C/C++) element into the file represented by the VCFileCodeModel object.

See How to: Compile Example Code for Visual C++ Code Model Extensibility for information on how to compile and run this sample.

Applies to