通过pkName和对应的值,列表List-BaseModel中找到对应的BaseModel(递归树结构) - FindModelByListModel

2017-07-05 13:57:39  访问(1425) 赞(0) 踩(0)


        /// <summary>
        /// 通过pkName和对应的值,列表List-BaseModel中找到对应的BaseModel(递归树结构) - FindModelByListModel
        /// </summary>
        /// <param name="theList">列表List-BaseModel</param>
        /// <param name="pkName">字段名</param>
        /// <param name="strId">字段值</param>
        /// <returns>找到第一条BaseModel,没有返回null</returns>
        protected BaseModel FindModelByListModel
            (List<BaseModel> theList,string pkName, string strId)
        {
            if (theList == null)
                return null;

            BaseModel theResult = null;

            foreach (BaseModel model in theList)
            {
                if (model.GetPropertyStrValue(pkName) == strId)
                    return model;

                theResult = FindModelByListModel(model.GetListSon(), pkName, strId);

                if (theResult != null)
                    return theResult;
            }

            return null;
        }


上一条:

下一条:


 

相关评论

评论加载中……
 

发表评论

类型:
内容:
  (Alt+Enter)