IHierarchyDataとは? わかりやすく解説

IHierarchyData インターフェイス

メモ : このインターフェイスは、.NET Framework version 2.0新しく追加されたものです。

階層データ構造ノード公開しますノード オブジェクトと、そのノード特性を示すいくつかのプロパティ含まれます。IHierarchyData インターフェイス実装するオブジェクトは、IHierarchicalEnumerable コレクション格納でき、ASP.NET サイト ナビゲーションデータ ソース コントロールによって使用されます。

名前空間: System.Web.UI
アセンブリ: System.Web (system.web.dll 内)
構文構文

Dim instance As IHierarchyData
public interface IHierarchyData
public interface class IHierarchyData
public interface IHierarchyData
public interface IHierarchyData
解説解説
使用例使用例

FileSystemInfo オブジェクトラップするクラスIHierarchyData インターフェイス実装する方法次のコード例示しますFileSystemInfo クラスは、IHierarchyData インターフェイスASP.NET 階層データ ソース コントロールに対して表す階層データ ノード良い例です。このコード例は、HierarchicalDataSourceControl クラストピック取り上げているコード例一部分です。

Public Class FileSystemHierarchyData
   Implements IHierarchyData

   Public Sub New(obj As
 FileSystemInfo)
      fileSystemObject = obj
   End Sub 'New

   Private fileSystemObject As FileSystemInfo
 = Nothing

   Public Overrides Function
 ToString() As String
      Return fileSystemObject.Name
   End Function 'ToString

   ' IHierarchyData implementation.
   Public Overridable ReadOnly
 Property HasChildren() As Boolean
 _
    Implements IHierarchyData.HasChildren
      Get
         If GetType(DirectoryInfo) Is
 fileSystemObject.GetType() Then
            Dim temp As DirectoryInfo = CType(fileSystemObject,
 DirectoryInfo)
            Return temp.GetFileSystemInfos().Length > 0
         Else
            Return False
         End If
      End Get
   ' DirectoryInfo returns the OriginalPath, while FileInfo returns
   ' a fully qualified path.

   Public Overridable ReadOnly
 Property Path() As String
 _
    Implements IHierarchyData.Path
      Get
         Return fileSystemObject.ToString()
      End Get
   End Property

   Public Overridable ReadOnly
 Property Item() As Object
 _
    Implements IHierarchyData.Item
      Get
         Return fileSystemObject
      End Get
   End Property

   Public Overridable ReadOnly
 Property Type() As String
 _
    Implements IHierarchyData.Type
      Get
         Return "FileSystemData"
      End Get
   End Property

   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 'FileSystemHierarchyData
public class FileSystemHierarchyData : IHierarchyData
{
    public FileSystemHierarchyData (FileSystemInfo obj) {
        fileSystemObject = obj;
    }

    private FileSystemInfo fileSystemObject = null;

    public override string ToString() {
        return fileSystemObject.Name;
    }
    // IHierarchyData implementation.
    public bool HasChildren {
        get {
            if (typeof(DirectoryInfo) ==  fileSystemObject.GetType()
   ) {
                DirectoryInfo temp = (DirectoryInfo) fileSystemObject;
                return (temp.GetFileSystemInfos().Length >
 0);
            }
            else return false;
        }
    }
    // DirectoryInfo returns the OriginalPath, while FileInfo returns
    // a fully qualified path.
    public string Path {
        get {
            return fileSystemObject.ToString();
        }
    }
    public object Item {
        get {
            return fileSystemObject;
        }
    }
    public string Type {
        get {
            return "FileSystemData";
        }
    }
    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;
    }
}

IHierarchicalEnumerable コレクション再帰的反復処理し、GetHierarchyData メソッド使用して IHierarchyData 項目を列挙体から抽出し、そのデータ項目に対して基本操作実行する方法次のコード例示します

<%@ Page Language="VB" AutoEventWireup="true"
 CodeFile="ihd_1.aspx.vb" Inherits="ihd_1_aspx"
 %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML
 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html  >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
    </div>
    </form>
</body>
</html>
<%@ Page Language="C#" AutoEventWireup="true"
 CodeFile="ihd_1.aspx.cs" Inherits="ihd_1_aspx" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html  >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
    </div>
    </form>
</body>
</html>
<%@ Page Language="VJ#"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<SCRIPT runat="server">
    private void Page_Load(Object sender, System.EventArgs
 e)
    {
        IHierarchicalEnumerable ihe = 
            (IHierarchicalEnumerable)SiteMap.get_RootNode().get_ChildNodes();
        IEnumerator enumeration = ihe.GetEnumerator();

        while (enumeration.MoveNext()) {
            // Print out SiteMapNode Titles.
            IHierarchyData hierarchicalNode = 
                ihe.GetHierarchyData(enumeration.get_Current());
            PrintFullChildNodeInfo(hierarchicalNode);
        }
    }//Page_Load
    // Print out the the current data node, then iterate through its
    // children and do the same.
    private void PrintFullChildNodeInfo(IHierarchyData
 node)
    {
        String whitespace = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
        String br = "<BR>";

        get_Response().Write(node.toString() + br);
        get_Response().Write(whitespace + node.get_Path() + br);

        // Check for specific types and perform extended functions.
        if (node.get_Type().Equals("SiteMapNode")) {
            // Because SiteMapNode implements the IHierarchyData interface
,
            // the IHierarchyData object can be cast directly as a SiteMapNode
,
            // rather than accessing the Item property for the object
 that
            // the Type property identifies.
            SiteMapNode siteNode = null;

            siteNode = (SiteMapNode)node.get_Item();
            get_Response().Write(whitespace + siteNode.get_Url() + br);
            get_Response().Write(whitespace + siteNode.get_Description() + br);
        }
        else {
            if (node.get_Type().Equals("SomeBusinessObject"))
 {
                // If the IHierarchyData instance is a wrapper class
 on a
                // business object of some kind, you can retrieve the
 business
                // object by using the IHierarchyData.Item property.
                // SomeBusinessObject busObj = node.Item as SomeBusinessObject;
            }
        }
        if (node.get_HasChildren()) {
            IEnumerator children = 
                ((IHierarchicalEnumerable)node.GetChildren()).GetEnumerator();

            while (children.MoveNext()) {
                // Print out SiteMapNode Titles recursively.
                IHierarchyData hierarchicalNode = 
                    node.GetChildren().GetHierarchyData(children.get_Current());
                PrintFullChildNodeInfo(hierarchicalNode);
            }
        }
    }//PrintFullChildNodeInfo
    
</SCRIPT>

<HTML>
    <BODY>
        <FORM runat="server">

        </FORM>
    </BODY>
</HTML>
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
IHierarchyData メンバ
System.Web.UI 名前空間
IHierarchicalEnumerable インターフェイス
SiteMapNode

IHierarchyData プロパティ


パブリック プロパティパブリック プロパティ

参照参照

関連項目

IHierarchyData インターフェイス
System.Web.UI 名前空間
IHierarchicalEnumerable インターフェイス
SiteMapNode

IHierarchyData メソッド


IHierarchyData メンバ



このページでは「.NET Framework クラス ライブラリ リファレンス」からIHierarchyDataを検索した結果を表示しています。
Weblioに収録されているすべての辞書からIHierarchyDataを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からIHierarchyData を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「IHierarchyData」の関連用語

IHierarchyDataのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



IHierarchyDataのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS