IHierarchyData.Type 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
public:
property System::String ^ Type { System::String ^ get(); };
public string Type { get; }
member this.Type : string
Public ReadOnly Property Type As String
属性值
IHierarchyData 对象表示的对象的类型的名称。
示例
下面的代码示例演示如何将基本IHierarchyData属性HttpResponse写入流,然后使用属性检查对象的类型,并强制转换对象Type以执行更多特定于类型的IHierarchyData操作。 此代码示例是为接口提供的大型示例的 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
注解
该 Type 属性不返回 System.Type 对象中 IHierarchyData 表示的对象。 它返回数据绑定控件用来区分层次结构中具有不同可绑定属性的项的名称。