更新:2007 年 11 月
获取代码元素的集合。
命名空间:  EnvDTE
程序集:  EnvDTE(在 EnvDTE.dll 中)
语法
声明
ReadOnly Property CodeElements As CodeElements
用法
Dim instance As FileCodeModel
Dim value As CodeElements
value = instance.CodeElements
CodeElements CodeElements { get; }
property CodeElements^ CodeElements {
    CodeElements^ get ();
}
function get CodeElements () : CodeElements
属性值
一个 CodeElements 集合。
示例
Sub CodeElementsExample(ByVal dte As DTE2)
    ' Before running this example, open a code document from a project.
    Try
        Dim fcm As FileCodeModel = _
            dte.ActiveDocument.ProjectItem.FileCodeModel
        ' Find the FileCodeModel's children.
        Dim children As String
        Dim elem As CodeElement
        For Each elem In fcm.CodeElements
            children &= elem.Name & vbCrLf
        Next
        MsgBox(fcm.Parent.Name & _
            " has the following top-level code elements:" & _
            vbCrLf & vbCrLf & children)
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try
End Sub
public void CodeElementsExample(DTE2 dte)
{
    // Before running this example, open a code document from 
    // a project.
    try
    {
        FileCodeModel fcm = 
            dte.ActiveDocument.ProjectItem.FileCodeModel;
        // Find the FileCodeModel's children.
        string children = "";
        foreach (CodeElement elem in fcm.CodeElements)
        {
            children += elem.Name + Environment.NewLine;
        }
        MessageBox.Show(fcm.Parent.Name + 
            " has the following top-level code elements:" + 
            Environment.NewLine + Environment.NewLine + children);
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
}
权限
- 对直接调用方的完全信任。此成员不能由部分信任的代码使用。有关更多信息,请参见通过部分受信任的代码使用库。