CodeAttribute2.Children 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取此代码构造中包含的对象的集合。
public:
property EnvDTE::CodeElements ^ Children { EnvDTE::CodeElements ^ get(); };
[System.Runtime.InteropServices.DispId(8)]
public EnvDTE.CodeElements Children { [System.Runtime.InteropServices.DispId(8)] [System.Runtime.InteropServices.TypeLibFunc(1024)] get; }
[<System.Runtime.InteropServices.DispId(8)>]
[<get: System.Runtime.InteropServices.DispId(8)>]
[<get: System.Runtime.InteropServices.TypeLibFunc(1024)>]
member this.Children : EnvDTE.CodeElements
Public ReadOnly Property Children As CodeElements
属性值
返回 CodeElements 集合。
实现
- 属性
示例
下面的示例在当前类中创建新的命名空间和属性,并列出属性的一些属性。
Sub Children2Example(ByVal dte As DTE2)
' Before running this example, open a code page of a project
' and place the insertion point inside a namespace definition.
Try
' Retrieve the CodeNamespace at the insertion point.
Dim sel As TextSelection = _
CType(dte.ActiveDocument.Selection, TextSelection)
Dim spc As CodeNamespace = _
CType(sel.ActivePoint.CodeElement( _
vsCMElement.vsCMElementNamespace), CodeNamespace)
' Find the namespace's children.
Dim children As String
Dim elem As CodeElement
For Each elem In spc.Children
children &= elem.Name & vbCrLf
Next
MsgBox(spc.Name & " has the following child code elements:" & _
vbCrLf & vbCrLf & children)
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
public void Children2Example(DTE2 dte)
{
// Before running this example, open a code document from a project
// and place the insertion point inside a namespace definition.
try
{
// Retrieve the CodeNamespace at the insertion point.
TextSelection sel =
(TextSelection)dte.ActiveDocument.Selection;
CodeNamespace spc =
(CodeNamespace)sel.ActivePoint.get_CodeElement(
vsCMElement.vsCMElementNamespace);
// Find the namespace's children.
string children = "";
foreach (CodeElement elem in spc.Children)
children += elem.Name + "\r\n";
MessageBox.Show(spc.Name +
" has the following child code elements:" + "\r\n\r\n" +
children);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
注解
如果对象没有任何子级,则 Nothing 返回或 null 。
此属性主要由 Visual C++ 使用。 Children属性从代码元素返回每个对象可再用。 例如,类返回成员、基、实现的接口、特性、注释等。
若要遍历命名空间的成员或类型 (类、结构、接口等) ,必须 () QI 查询接口,或将对象强制转换 CodeElement 为 CodeNamespace 对象,然后使用 Members 属性。
Children属性返回 CodeElement2 可通过此代码元素引用的所有相关对象的集合。 例如,对于 CodeClass2 对象,这可能包括类的元数据代码元素,可能包括 Visual C++ declspecs,以及基于 Visual C++、模板参数等中的特性化编程功能提供的代码。 CodeFunction2对象可能包含其所有参数、基于特性化编程功能的提供参数等。
Children属性可能返回 Nothing 或, null 具体取决于对象和语言。 在 Visual Studio 中不需要支持此项。