CodeClass.Members 属性
获取此元素包含的项的集合。
命名空间: EnvDTE
程序集: EnvDTE(在 EnvDTE.dll 中)
语法
声明
ReadOnly Property Members As CodeElements
CodeElements Members { get; }
property CodeElements^ Members {
CodeElements^ get ();
}
abstract Members : CodeElements
function get Members () : CodeElements
属性值
类型:EnvDTE.CodeElements
一个 CodeElements 集合。
备注
当代码类型种类为 vsCMElementDelegate 时,Members 属性失败,原因是委托在源代码中没有成员。 它们是由编译器和 .NET Framework 提供的。
备注
在进行某些类型的编辑之后,代码模型元素(如类、结构、函数、特性、委托等)的值可能是非确定性的,这意味着不能指望它们的值总是保持不变。有关更多信息,请参见 使用代码模型查找代码 (Visual Basic) 中的“代码模型元素的值可能会更改”一节。
示例
Public Sub CodeClassExample(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
Dim objTextSel As TextSelection
Dim objCodeCls As CodeClass
objTextSel = CType(dte.ActiveDocument.Selection, TextSelection)
objCodeCls = CType(objTextSel.ActivePoint.CodeElement(vsCMElement.vsCMElementClass), CodeClass)
' Add comments to CodeClass objCodeClass - notice change in code document.
objCodeCls.Comment = "Comments for the CodeClass object."
' Access top-level object through the CodeClass object
' and return the file name of that top-level object.
MessageBox.Show("Top-level object's filename: " + objCodeCls.DTE.FileName)
' Get the language used to code the CodeClass object - returns a GUID.
MessageBox.Show(objCodeCls.Language)
' Get a collection of elements contained by the CodeClass object.
Dim members As String = "Member Elements of " + objCodeCls.Name + ": " + vbCrLf
Dim elem As CodeElement
For Each elem In objCodeCls.Members
members = members + (elem.Name + vbCrLf)
Next elem
MessageBox.Show(members)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
public void CodeClassExample(DTE2 dte)
{
// Before running this example, open a code document from a
// project and place the insertion point inside a class definition.
try
{
TextSelection objTextSel;
CodeClass objCodeCls;
objTextSel = (TextSelection)dte.ActiveDocument.Selection;
objCodeCls = (CodeClass)objTextSel.ActivePoint.get_CodeElement(vsCMElement.vsCMElementClass);
// Add comments to CodeClass objCodeClass - notice change in code document.
objCodeCls.Comment = "Comments for the CodeClass object.";
// Access top-level object through the CodeClass object
// and return the file name of that top-level object.
MessageBox.Show("Top-level object's filename: " + objCodeCls.DTE.FileName);
// Get the language used to code the CodeClass object - returns a GUID.
MessageBox.Show(objCodeCls.Language);
// Get a collection of elements contained by the CodeClass object.
string members = "Member Elements of " + objCodeCls.Name + ": \n";
foreach (CodeElement elem in objCodeCls.Members)
{
members = members + (elem.Name + "\n");
}
MessageBox.Show(members);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
.NET Framework 安全性
- 对直接调用方的完全信任。此成员不能由部分信任的代码使用。有关更多信息,请参见通过部分受信任的代码使用库。