Share via


FileCodeModel.Remove Method

Removes the specified code element from the source file.

Namespace:  EnvDTE
Assembly:  EnvDTE (in EnvDTE.dll)

Syntax

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

Parameters

  • Element
    Type: System.Object
    Required. A CodeElement object or the name of a code element to remove from the source code.

Remarks

Element can be either a CodeElement object in the collection, or the name of a unique element in the collection.

Individual elements do not have a Remove method because they can exist in multiple collections. To remove a specific element, you must call the Remove method of its container object.

Examples

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 Security

See Also

Reference

FileCodeModel Interface

EnvDTE Namespace

Other Resources

How to: Compile and Run the Automation Object Model Code Examples