CodeAttribute2.Children 屬性
取得這個程式碼建構內物件的集合。
命名空間: EnvDTE80
組件: EnvDTE80 (在 EnvDTE80.dll 中)
語法
'宣告
ReadOnly Property Children As CodeElements
Get
CodeElements Children { get; }
property CodeElements^ Children {
CodeElements^ get ();
}
abstract Children : CodeElements
function get Children () : CodeElements
屬性值
型別:EnvDTE.CodeElements
傳回 CodeElements 集合。
實作
備註
如果物件沒有子系,則傳回 Nothing 或 nullNull 參照 (即 Visual Basic 中的 Nothing)。
這個屬性主要是由 Visual C++ 所用。 Children 屬性會從程式碼項目傳回每個可傳回的物件。 例如,類別會傳回成員、基底、實作介面、屬性、註解等等。
若要逐一查看命名空間或型別 (類別、結構、介面等等) 的成員,則必須查詢介面 (QI) 或將 CodeElement 物件轉型為 CodeNamespace 物件,然後再使用 Members 屬性。
Children 屬性會傳回所有可以透過這個程式碼項目參考的相關 CodeElement2 物件之集合。 例如,對於 CodeClass2 物件而言,這可能包括類別的中繼資料程式碼項目,甚至可能包括 Visual C++ 的 Declspec,以及依 Visual C++ 中的屬性化程式開發功能所提供的程式碼、範本參數等。 CodeFunction2 物件可能包括其所有的參數、依屬性化程式開發功能所提供的參數等。
因物件和程式語言的不同,Children 屬性可能傳回 Nothing 或 null 。 這在 Visual Studio 中任何情況下都能支援。
範例
下列範例會在目前的類別中建立新的命名空間和屬性,並列出屬性 (Attribute) 的部分屬性 (Property)。
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);
}
}
.NET Framework 安全性
- 完全信任立即呼叫者。這個成員無法供部分信任的程式碼使用。如需詳細資訊,請參閱從部分受信任程式碼使用程式庫。