ProjectItem.Name Eigenschaft

Definition

Ruft den Namen des Objekts ab oder legt ihn fest.Gets or sets the name of the object.

public:
 property System::String ^ default { System::String ^ get(); void set(System::String ^ value); };
public:
 property Platform::String ^ default { Platform::String ^ get(); void set(Platform::String ^ value); };
[System.Runtime.InteropServices.DispId(0)]
public string this { [System.Runtime.InteropServices.DispId(0)] get; [System.Runtime.InteropServices.DispId(0)] set; }
[<System.Runtime.InteropServices.DispId(0)>]
[<get: System.Runtime.InteropServices.DispId(0)>]
[<set: System.Runtime.InteropServices.DispId(0)>]
member this.Name : string with get, set
Default Public Property Name As String

Eigenschaftswert

String

Eine Zeichenfolge, die den Namen des Objekts darstellt.A string representing the name of the object.

Attribute

Beispiele

Sub NameExample(ByVal dte As DTE2)  

    ' NOTE: This example requires a reference to the System.Text   
    '       namespace.  

    ' Before running this example, open a code document from a project.  
    Dim item As ProjectItem = dte.ActiveDocument.ProjectItem  
    Dim sb As New StringBuilder  

    RecurseElements(item.FileCodeModel.CodeElements, 0, sb)  

    MsgBox(item.Name & " contains the following elements:" & vbCrLf & _  
        vbCrLf & sb.ToString())  

End Sub  

Sub RecurseElements(ByVal elems As CodeElements, _  
    ByVal level As Integer, ByVal sb As StringBuilder)  

    Dim elem As CodeElement  
    For Each elem In elems  
        ' Add element to the list of names.  
        sb.Append(" "c, level * 8)  
        sb.Append(elem.Name & " [" & elem.Kind.ToString() & "]" & _  
            vbCrLf)  

        ' Call this function recursively if element has children.  
        If elem.Kind = vsCMElement.vsCMElementNamespace Then  
            RecurseElements(CType(elem, CodeNamespace).Members, _  
                level + 1, sb)  
        ElseIf elem.IsCodeType Then  
            RecurseElements(CType(elem, CodeType).Members, _  
                level + 1, sb)  
        End If  
    Next  

End Sub  
public void NameExample(DTE2 dte)  
{  
    // NOTE: This example requires a reference to the   
    //       System.Text namespace.  

    // Before running this example, open a code document from   
    // a project.  
    ProjectItem item = dte.ActiveDocument.ProjectItem;  
    StringBuilder sb = new StringBuilder();  

    RecurseElements(item.FileCodeModel.CodeElements, 0, sb);  
    MessageBox.Show(item.Name +   
        " contains the following elements:\n\n" + sb.ToString());  
}  

void RecurseElements(CodeElements elems, int level, StringBuilder sb)  
{  
    foreach (CodeElement elem in elems)  
    {  
        // Add element to the list of names.  
        sb.Append(' ', level * 8);  
        sb.Append(elem.Name + " [" + elem.Kind.ToString() + "]\n");  

        // Call this function recursively if element has children.  
        if (elem.Kind == vsCMElement.vsCMElementNamespace)  
            RecurseElements(((CodeNamespace)elem).Members,   
                level + 1, sb);  
        else if (elem.IsCodeType)  
            RecurseElements(((CodeType)elem).Members, level + 1, sb);  
    }  
}  

Gilt für: