EditPoint.CodeElement[vsCMElement] 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
在 EditPoint 位置获取代码元素。
public:
property EnvDTE::CodeElement ^ CodeElement[EnvDTE::vsCMElement] { EnvDTE::CodeElement ^ get(EnvDTE::vsCMElement Scope); };
[System.Runtime.InteropServices.DispId(51)]
public EnvDTE.CodeElement CodeElement[EnvDTE.vsCMElement Scope] { [System.Runtime.InteropServices.DispId(51)] get; }
[<System.Runtime.InteropServices.DispId(51)>]
[<get: System.Runtime.InteropServices.DispId(51)>]
member this.CodeElement(EnvDTE.vsCMElement) : EnvDTE.CodeElement
Public ReadOnly Property CodeElement(Scope As vsCMElement) As CodeElement
参数
- Scope
- vsCMElement
必需。 一个 vsCMElement 常数,它指示包含编辑器位置且具有指定类型的代码元素。
属性值
CodeElement 对象。
实现
- 属性
示例
Sub CodeElementExample(ByVal dte As DTE2)
' Before running this example, open a code document from a project
' and place the insertion point anywhere inside the source code.
Try
Dim sel As TextSelection = _
CType(dte.ActiveDocument.Selection, TextSelection)
Dim pnt As TextPoint = CType(sel.ActivePoint, TextPoint)
' Discover every code element containing the insertion point.
Dim elems As String
Dim elem As CodeElement
Dim scope As vsCMElement
For Each scope In [Enum].GetValues(scope.GetType())
elem = pnt.CodeElement(scope)
If IsNothing(elem) = False Then
elems &= elem.Name & _
" (" & scope.ToString() & ")" & vbCrLf
End If
Next
MsgBox("The following elements contain the insertion point:" _
& vbCrLf & vbCrLf & elems)
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
public void CodeElementExample(DTE2 dte)
{
// Before running this example, open a code document from a project
// and place the insertion point anywhere inside the source code.
try
{
TextSelection sel =
(TextSelection)dte.ActiveDocument.Selection;
TextPoint pnt = (TextPoint)sel.ActivePoint;
// Discover every code element containing the insertion point.
string elems = "";
vsCMElement scopes = 0;
foreach (vsCMElement scope in Enum.GetValues(scopes.GetType()))
{
CodeElement elem = pnt.CodeElement(scope);
if (elem != null)
elems += elem.Name +
" (" + scope.ToString() + ")\n";
}
MessageBox.Show(
"The following elements contain the insertion point:\n\n"
+ elems);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
注解
如果指定的代码元素类型不在该 EditPoint 位置,则 CodeElement 返回 Nothing 。 CodeElement 是的快捷方式 TextPoint.Parent.Parent.ProjectItem.CodeModel.CodeElementFromPoint(TextPoint, <scope>)