CodeClass2.Parent 属性

定义

获取类的直接父对象。

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

属性值

Object

表示类的父级的对象。

实现

属性

示例

[C#]

public void CodeClass2ParentExample(DTE2 dte2)  
{  
    // Before running this example, open a code document from a project  
    // and place the insertion point within a class definition.  
    try  
    {   // Get the CodeClass2 at the insertion point.  
        TextSelection sel =   
        (TextSelection)dte2.ActiveDocument.Selection;  
        CodeClass2 cls = (CodeClass2)sel.ActivePoint.get_CodeElement(  
            vsCMElement.vsCMElementClass);  
        // Get the parent object.  
        CodeElement ce = (CodeElement)cls.Parent;  
        MessageBox.Show(ce.Name.ToString());  
    }  
    catch (Exception e)  
    {  
        MessageBox.Show(e.Message);  
    }  
}  

注解

Parent属性返回类的直接父级。 如果要获取包含集合,则使用 Collection 属性。

备注

在进行了某些类型的编辑之后,代码模型元素(例如类、结构、函数、特性、委托等)的值可能变为非确定性的,这意味着不能确定它们的值始终保持不变。 有关详细信息,请参阅 "代码模型元素值在 使用代码模型查找代码时 可能发生变化" (Visual Basic) "。

适用于