我有一个名为MenuModel的类,其中包含:ParentID,MenuID,MenuDescription和Children(这是一个List(Of MenuModel)
我现在有了Grand-child(或更深层)的MenuID,我现在想检查一下Parent是否有那个孩子。
MenuItem.Children.Find(例如),但它必须以递归方式检查孩子中孩子的任何孩子,直到没有更多孩子要检查的水平。
有人能指出我正确的方向吗?
这是MenuModel:
Public Class MenuModel
Public ReadOnly Property Read() As IEnumerable(Of MenuModel)
Get
m_Menu = (database loads stuff into the object)
m_Menu = CreateVM("", m_Menu)
Return m_Menu
End Get
End Property
Private m_Menu As IEnumerable(Of MenuModel)
Private Function CreateVM(ParentObject As String, source As IEnumerable(Of MenuModel)) As List(Of MenuModel)
Return (From men In source Where men.ParentObject = ParentObject
Select New MenuModel With {
.ParentObject = men.ParentObject,
.MenuObject = men.MenuObject,
.MenuDescription = men.MenuDescription,
.MenuURL = men.MenuURL,
.MenuFeatures = men.MenuFeatures,
.MenuTarget = men.MenuTarget,
.MenuSequence = men.MenuSequence,
.MenuActive = men.MenuActive,
.Children = CreateVM(men.MenuObject, source)
}).ToList
End Function
Public Property Children() As List(Of MenuModel)
Get
Return m_Children
End Get
Set(value As List(Of MenuModel))
m_Children = value
End Set
End Property
Private m_Children As IEnumerable(Of MenuModel)
Public Property ParentObject() As String
Get
Return m_ParentObject
End Get
Set(value As String)
m_ParentObject = value
End Set
End Property
Private m_ParentObject As String
Public Property MenuObject() As String
Get
Return m_MenuObject
End Get
Set(value As String)
m_MenuObject = value
End Set
End Property
Private m_MenuObject As String
Public Property MenuDescription() As String
Get
Return m_MenuDescription
End Get
Set(value As String)
m_MenuDescription = value
End Set
End Property
Private m_MenuDescription As String
Public Property MenuURL() As String
Get
Return m_MenuURL
End Get
Set(value As String)
m_MenuURL = value
End Set
End Property
Private m_MenuURL As String
Public Property MenuTarget() As String
Get
Return m_MenuTarget
End Get
Set(value As String)
m_MenuTarget = value
End Set
End Property
Private m_MenuTarget As String
Public Property MenuFeatures() As String
Get
Return m_MenuFeatures
End Get
Set(value As String)
m_MenuFeatures = value
End Set
End Property
Private m_MenuFeatures As String
Public Property MenuSequence() As String
Get
Return m_MenuSequence
End Get
Set(value As String)
m_MenuSequence = value
End Set
End Property
Private m_MenuSequence As String
Public Property MenuActive() As String
Get
Return m_MenuActive
End Get
Set(value As String)
m_MenuActive = value
End Set
End Property
Private m_MenuActive As String
结束班