VCCodeModel.AddInclude 方法
将一个 #include 元素添加到特定文件。
命名空间: Microsoft.VisualStudio.VCCodeModel
程序集: Microsoft.VisualStudio.VCCodeModel(在 Microsoft.VisualStudio.VCCodeModel.dll 中)
语法
声明
Function AddInclude ( _
Name As String, _
Location As Object, _
Position As Object _
) As VCCodeInclude
VCCodeInclude AddInclude(
string Name,
Object Location,
Object Position
)
VCCodeInclude^ AddInclude(
String^ Name,
Object^ Location,
Object^ Position
)
abstract AddInclude :
Name:string *
Location:Object *
Position:Object -> VCCodeInclude
function AddInclude(
Name : String,
Location : Object,
Position : Object
) : VCCodeInclude
参数
Name
类型:String必需。 指定要包括的文件的名称(放在引号或尖括号中)。
Location
类型:Object必需。 要修改的文件的路径或文件名。 如果文件不存在,则自动创建该文件。 如果该文件还不是项目项,则将该文件添加到项目中。 如果无法创建该文件并将其添加到项目中,则 AddInclude 失败。
Position
类型:Object必需。 默认值 = 0。 将在其后添加新元素的代码元素。 如果该值为 CodeElement,则紧跟在其后添加新元素。
因为集合从 1 开始计数,所以传递 0 表示应将新元素放置在集合的开始处。 值为 -1 表示应将元素放在结尾处。
返回值
类型:Microsoft.VisualStudio.VCCodeModel.VCCodeInclude
一个 VCCodeInclude 对象。
备注
称此功能插入 #include 指令 (C/C++) 元素。VCCodeModel 对象中指定的文件中。
有关如何编译和运行此示例的信息,请参见 如何:编译 Visual C++ 代码模型扩展性的示例代码。
示例
此示例添加一个 #include 语句添加到 stdafx.h 文件。
Sub AddInclude()
Dim codeModel As VCCodeModel
codeModel = DTE.Solution.Item(1).CodeModel
Dim include As VCCodeInclude
include = codeModel.AddInclude("""stdafx.h""", "File.h", 0)
End Sub
.NET Framework 安全性
- 对直接调用方的完全信任。此成员不能由部分信任的代码使用。有关详细信息,请参阅通过部分受信任的代码使用库。