CodeClass.Parent 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取 CodeClass 对象的直接父对象。
public:
property System::Object ^ Parent { System::Object ^ get(); };
public:
property Platform::Object ^ Parent { Platform::Object ^ get(); };
[System.Runtime.InteropServices.DispId(31)]
public object Parent { [System.Runtime.InteropServices.DispId(31)] [System.Runtime.InteropServices.TypeLibFunc(1024)] get; }
[<System.Runtime.InteropServices.DispId(31)>]
[<get: System.Runtime.InteropServices.DispId(31)>]
[<get: System.Runtime.InteropServices.TypeLibFunc(1024)>]
member this.Parent : obj
Public ReadOnly Property Parent As Object
属性值
对象的直接父对象 CodeClass 。
- 属性
示例
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
Dim objCodeElem As CodeElement
objTextSel = CType(dte.ActiveDocument.Selection, TextSelection)
objCodeCls = CType(objTextSel.ActivePoint.CodeElement(vsCMElement.vsCMElementClass), CodeClass)
' Display the fullname of CodeClass object.
MessageBox.Show(objCodeCls.FullName)
' Prove that the parent object of a CodeClass is a CodeElement.
objCodeElem = CType(objCodeCls.Parent, CodeElement)
' Get access privilege for CodeClass.
MessageBox.Show(objCodeCls.Access.ToString())
' Change access privilege for CodeClass objCodeCls.
' Note the change in access keyword in your code document.
objCodeCls.Access = vsCMAccess.vsCMAccessPublic
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;
CodeElement objCodeElem;
objTextSel = (TextSelection)dte.ActiveDocument.Selection;
objCodeCls = (CodeClass)objTextSel.ActivePoint.get_CodeElement(vsCMElement.vsCMElementClass);
// Display the fullname of CodeClass object.
MessageBox.Show(objCodeCls.FullName);
// Prove that the parent object of a CodeClass is a CodeElement.
objCodeElem = (CodeElement)objCodeCls.Parent;
// Get access privilege for CodeClass.
MessageBox.Show(objCodeCls.Access.ToString());
// Change access privilege for CodeClass objCodeCls.
// Note the change in access keyword in your code document.
objCodeCls.Access = vsCMAccess.vsCMAccessPublic;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
注解
Parent属性将直接父级返回给 CodeClass 对象。 若要获取包含集合,请使用 Collection 属性。
备注
在进行了某些类型的编辑之后,代码模型元素(例如类、结构、函数、特性、委托等)的值可能变为非确定性的,这意味着不能确定它们的值始终保持不变。 有关详细信息,请参阅 "代码模型元素值在 使用代码模型查找代码时 可能发生变化" (Visual Basic) "。