IHierarchyData.Type Propriété

Définition

Obtient le nom du type de Object contenu dans la propriété Item.

public:
 property System::String ^ Type { System::String ^ get(); };
public string Type { get; }
member this.Type : string
Public ReadOnly Property Type As String

Valeur de propriété

String

Nom du type d'objet que l'objet IHierarchyData représente.

Exemples

L’exemple de code suivant montre comment écrire les propriétés de base IHierarchyData dans un HttpResponse flux, puis vérifier le type d’un IHierarchyData objet à l’aide de la Type propriété et caster l’objet pour effectuer des opérations plus spécifiques au type. Cet exemple de code fait partie d’un exemple plus grand fourni pour l’interface IHierarchyData .

// 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 = "     "
    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

Remarques

La Type propriété ne retourne pas l’objet System.Type représenté dans un IHierarchyData objet. Elle retourne un nom utilisé par les contrôles liés aux données pour différencier les éléments d’une hiérarchie qui ont des propriétés pouvant être liées différentes.

S’applique à

Voir aussi