Share via


FileCodeModel.Remove 方法

从源文件移除指定的代码元素。

命名空间:  EnvDTE
程序集:  EnvDTE(在 EnvDTE.dll 中)

语法

声明
Sub Remove ( _
    Element As Object _
)
void Remove(
    Object Element
)
void Remove(
    Object^ Element
)
abstract Remove : 
        Element:Object -> unit
function Remove(
    Element : Object
)

参数

  • Element
    类型:Object

    必选。 要从源代码中移除的 CodeElement 对象或代码元素的名称。

备注

Element 可以是集合中的 CodeElement 对象,或者是集合中某唯一元素的名称。

由于单个元素可能存在于多个集合中,因此没有与之对应的 Remove 方法。 若要移除特定元素,必须调用其容器对象的 Remove 方法。

示例

Sub RemoveExample(ByVal dte As DTE2)

    ' Before running this example, open a code document from a project
    ' and place the insertion point inside a function.
    Try
        ' Retrieve the CodeFunction at the insertion point.
        Dim sel As TextSelection = _
            CType(dte.ActiveDocument.Selection, TextSelection)
        Dim fun As CodeFunction = _
            CType(sel.ActivePoint.CodeElement( _
            vsCMElement.vsCMElementFunction), CodeFunction)

        If MsgBox("Remove " & fun.Name & "?", MsgBoxStyle.YesNo) = _
            MsgBoxResult.Yes Then
            ' Remove the function.
            fun.ProjectItem.FileCodeModel.Remove(fun)
        End If
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try

End Sub

.NET Framework 安全性

请参阅

参考

FileCodeModel 接口

EnvDTE 命名空间

其他资源

如何:编译和运行自动化对象模型代码示例