Condividi tramite


CodeClass2.AddEvent(String, String, Boolean, Object, vsCMAccess) Method

Definition

Adds a class event.

EnvDTE80::CodeEvent AddEvent(std::wstring const & Name, std::wstring const & FullDelegateName, bool CreatePropertyStyleEvent = false, winrt::Windows::Foundation::IInspectable const & Location, EnvDTE::vsCMAccess Access = EnvDTE.vsCMAccess.vsCMAccessDefault);
[System.Runtime.InteropServices.DispId(209)]
public EnvDTE80.CodeEvent AddEvent (string Name, string FullDelegateName, bool CreatePropertyStyleEvent = false, object Location, EnvDTE.vsCMAccess Access = EnvDTE.vsCMAccess.vsCMAccessDefault);
[<System.Runtime.InteropServices.DispId(209)>]
abstract member AddEvent : string * string * bool * obj * EnvDTE.vsCMAccess -> EnvDTE80.CodeEvent
Public Function AddEvent (Name As String, FullDelegateName As String, Optional CreatePropertyStyleEvent As Boolean = false, Optional Location As Object, Optional Access As vsCMAccess = EnvDTE.vsCMAccess.vsCMAccessDefault) As CodeEvent

Parameters

Name
String

Required. Name of the class event to add.

FullDelegateName
String

Required. Name of the delegate to base the event on. This acts as a template for the new event handler.

CreatePropertyStyleEvent
Boolean

Optional. Creates an event that has a property style accessor. True indicates that the event should have an accessor, false indicates that it should not.

Location
Object
Access
vsCMAccess

Optional. A vsCMAccess constant.

Returns

Returns the class event handler that was created.


The values of code model elements such as classes, structs, functions, attributes, delegates, and so forth can be non-deterministic after making certain kinds of edits, meaning that their values cannot be relied upon to always remain the same. For more information, see the section Code Model Element Values Can Change in Discovering Code by Using the Code Model (Visual Basic).

Attributes

Examples

[Visual Basic]

Sub AddEventExample(ByVal dte As DTE2)  
    ' Before running this example, open a code document from a project  
    ' and place the insertion point inside a class definition.  
    Try  
        ' Retrieve the CodeClass at the insertion point.  
        Dim sel As TextSelection = _  
            CType(dte.ActiveDocument.Selection, TextSelection)  
        Dim cls As CodeClass = _  
            CType(sel.ActivePoint.CodeElement( _  
            vsCMElement.vsCMElementClass), CodeClass)  

        ' Create a new event handler.  
        cls.AddEvent("NewOnConnection", "OnConnection", True, -1,   
          vsCMAccess.vsCMAccessPublic)  
    Catch ex As Exception  
        MsgBox(ex.Message)  
    End Try  
End Sub  

[C#]

public void AddEventExample(DTE2 dte)  
{  
    // Before running this example, open a code document from a project  
    // and place the insertion point inside a class definition.  
    try  
    {  
        // Retrieve the CodeClass at the insertion point.  
        TextSelection sel =   
            (TextSelection)dte.ActiveDocument.Selection;  
        CodeClass cls =   
            (CodeClass)sel.ActivePoint.get_CodeElement(  
            vsCMElement.vsCMElementClass);  
        // Creates a new event handler.  
        cls.AddEvent("NewOnConnection", "OnConnection", true, -1,   
          vsCMAccess.vsCMAccessPublic);  
    }  
    catch (Exception ex)  
    {  
        MessageBox.Show(ex.Message);  
    }  
}  

Applies to