IHierarchyData.GetParent メソッド

定義

現在の階層ノードの親ノードを表す IHierarchyData オブジェクトを取得します。Gets an IHierarchyData object that represents the parent node of the current hierarchical node.

public:
 System::Web::UI::IHierarchyData ^ GetParent();
public System.Web.UI.IHierarchyData GetParent ();
abstract member GetParent : unit -> System.Web.UI.IHierarchyData
Public Function GetParent () As IHierarchyData

戻り値

現在の階層ノードの親ノードを表す IHierarchyData オブジェクト。An IHierarchyData object that represents the parent node of the current hierarchical node.

次のコード例は、 GetParent IHierarchyDataインターフェイスを実装するクラスにメソッドを実装する方法を示しています。The following code example demonstrates how to implement the GetParent method in a class that implements the IHierarchyData interface. クラスFileSystemHierarchyData FileSystemInfoはオブジェクトをラップし、メソッドGetParentの実装はFileSystemInfoオブジェクトの型をチェックし、型に基づいて適切な親オブジェクトを返します。The FileSystemHierarchyData class wraps a FileSystemInfo object, and the GetParent method implementation checks the type of the FileSystemInfo object, and returns the appropriate parent object based on the type. このコード例は、 IHierarchyDataインターフェイスHierarchicalDataSourceControlおよびクラス用に用意されている大規模な例の一部です。This code example is part of a larger example provided for the IHierarchyData interface and the HierarchicalDataSourceControl class.

public IHierarchicalEnumerable GetChildren()
{
    FileSystemHierarchicalEnumerable children =
        new FileSystemHierarchicalEnumerable();

    if (typeof(DirectoryInfo) == fileSystemObject.GetType())
    {
        DirectoryInfo temp = (DirectoryInfo)fileSystemObject;
        foreach (FileSystemInfo fsi in temp.GetFileSystemInfos())
        {
            children.Add(new FileSystemHierarchyData(fsi));
        }
    }
    return children;
}

public IHierarchyData GetParent()
{
    FileSystemHierarchicalEnumerable parentContainer =
        new FileSystemHierarchicalEnumerable();

    if (typeof(DirectoryInfo) == fileSystemObject.GetType())
    {
        DirectoryInfo temp = (DirectoryInfo)fileSystemObject;
        return new FileSystemHierarchyData(temp.Parent);
    }
    else if (typeof(FileInfo) == fileSystemObject.GetType())
    {
        FileInfo temp = (FileInfo)fileSystemObject;
        return new FileSystemHierarchyData(temp.Directory);
    }
    // If FileSystemObj is any other kind of FileSystemInfo, ignore it.
    return null;
}
    Public Overridable Function GetChildren() _
        As IHierarchicalEnumerable _
        Implements IHierarchyData.GetChildren

        Dim children As New FileSystemHierarchicalEnumerable()

        If GetType(DirectoryInfo) Is fileSystemObject.GetType() Then
            Dim temp As DirectoryInfo = _
                CType(fileSystemObject, DirectoryInfo)
            Dim fsi As FileSystemInfo
            For Each fsi In temp.GetFileSystemInfos()
                children.Add(New FileSystemHierarchyData(fsi))
            Next fsi
        End If
        Return children
    End Function 'GetChildren


    Public Overridable Function GetParent() As IHierarchyData _
     Implements IHierarchyData.GetParent
        Dim parentContainer As New FileSystemHierarchicalEnumerable()

        If GetType(DirectoryInfo) Is fileSystemObject.GetType() Then
            Dim temp As DirectoryInfo = _
                CType(fileSystemObject, DirectoryInfo)
            Return New FileSystemHierarchyData(temp.Parent)
        ElseIf GetType(FileInfo) Is fileSystemObject.GetType() Then
            Dim temp As FileInfo = CType(fileSystemObject, FileInfo)
            Return New FileSystemHierarchyData(temp.Directory)
        End If
        ' If FileSystemObj is any other kind of FileSystemInfo, ignore it.
        Return Nothing
    End Function 'GetParent
End Class

注釈

インターフェイスIHierarchyDataは hasparent 便宜的プロパティを定義していないので、呼び出し元はのGetParentメソッドのnull戻り値をチェックしIHierarchyDataて、現在のノードが階層データのルートノードであるかどうかを判断する必要があります。ノードが属する構造体。The IHierarchyData interface does not define a HasParent convenience property, so callers must check the return value of the GetParent method for null to determine whether the current IHierarchyData node is the root node of the hierarchical data structure to which the node belongs.

適用対象

こちらもご覧ください