IHierarchyData.Item プロパティ

定義

IHierarchyData オブジェクトが表す階層データ ノードを取得します。Gets the hierarchical data node that the IHierarchyData object represents.

public:
 property System::Object ^ Item { System::Object ^ get(); };
public object Item { get; }
member this.Item : obj
Public ReadOnly Property Item As Object

プロパティ値

Object 階層データ ノード オブジェクト。An Object hierarchical data node object.

次のコード例は、プロパティにIHierarchyDataアクセスし、 Typeプロパティを使用しIHierarchyDataてオブジェクトの型を確認し、オブジェクトをキャストして、より多くの型固有の操作を実行する方法を示しています。The following code example demonstrates how to access IHierarchyData properties, check the type of an IHierarchyData object using the Type property, and cast the object to perform more type-specific operations. このコード例は、 IHierarchyDataインターフェイス用に用意されている大規模な例の一部です。This code example is part of a larger example provided for the IHierarchyData interface.

// Print out the current data node, then iterate through its
// children and do the same.
private void PrintFullChildNodeInfo(IHierarchyData node)
{
    string whitespace = "     ";
    string br = "<BR>";

    Response.Write(node.ToString() + br);
    Response.Write(whitespace + node.Path + br);

    // Check for specific types and perform extended functions.
    if (node.Type == "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 = node.Item as SiteMapNode;
        Response.Write(whitespace + siteNode.Url + br);
        Response.Write(whitespace + siteNode.Description + br);
    }
    else if (node.Type == "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.HasChildren)
    {
        IEnumerator children = ((IHierarchicalEnumerable)node.GetChildren()).GetEnumerator();

        while (children.MoveNext())
        {
            // Print out SiteMapNode Titles recursively.
            IHierarchyData hierarchicalNode = node.GetChildren().GetHierarchyData(children.Current);
            PrintFullChildNodeInfo(hierarchicalNode);
        }
    }
}
' Print out the current data node, then iterate through its
' children and do the same.

Private Sub PrintFullChildNodeInfo(ByVal node As IHierarchyData)
    Dim whitespace As String = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
    Dim br As String = "<BR>"

    Response.Write(Convert.ToString(node) & br)
    Response.Write(whitespace & node.Path & br)

    ' Check for specific types and perform extended functions.
    If node.Type = "SiteMapNode" Then
        ' 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.
        Dim siteNode As SiteMapNode = CType(node.Item, SiteMapNode)
        Response.Write(whitespace & siteNode.Url & br)
        Response.Write(whitespace & siteNode.Description & br)

    ElseIf node.Type = "SomeBusinessObject Then" Then
        ' 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;
    End If

    If node.HasChildren Then
        Dim children As IEnumerator = CType(node.GetChildren().GetEnumerator(), IHierarchicalEnumerable)
        While children.MoveNext()
            ' Print out SiteMapNode Titles recursively.
            Dim hierarchicalNode As IHierarchyData = node.GetChildren().GetHierarchyData(children.Current)
            PrintFullChildNodeInfo(hierarchicalNode)
        End While
    End If
End Sub

注釈

SiteMapNodeクラスなどの階層データノードを表す多くのクラスは、 IHierarchyDataインターフェイスを直接実装しますが、他のクラスは、インターフェイスを実装しないクラスのラッパーとしてのみ機能します。While many classes that represent hierarchical data nodes, such as the SiteMapNode class, implement the IHierarchyData interface directly, other classes only act as a wrapper for a class that does not implement the interface. ItemビジネスオブジェクトIHierarchyDataをオブジェクトと機能的に同等にすることはできますが、簡単に再設計することはできません。The Item property is provided for these design situations, when business objects are functionally equivalent to an IHierarchyData object but cannot be redesigned easily.

適用対象

こちらもご覧ください