private static void PutNodeAndChildNodes(ref ArrayList list, BaseEntity entity) { list.Add(entity); entity.Load(entity.Id, Fetch.REFSandSets); ArrayList clist = (ArrayList)entity.GetType().GetProperty("Child" + entity.GetType().Name + "s").GetValue(entity, null); if (clist != null && clist.Count > 0) { foreach (BaseEntity centity in clist) { PutNodeAndChildNodes(ref list, centity); } } }
/// <summary> /// 获取实体的父对象 /// </summary> /// <param name="objEntity">宿主实体</param> /// <param name="table">数据集</param> /// <param name="rIndex">取数据集的行数</param> public static void FetchParent(object objEntity, DataTable table, int rIndex) { EntityInfo einfo = DLLAnalysis.GetEntityInfoByType(objEntity.GetType()); object pid = table.Rows[rIndex]["PTId"]; if (pid == DBNull.Value || string.IsNullOrEmpty(pid.ToString())) { return; } BaseEntity pEntity = (BaseEntity)DLLAnalysis.GetEntityInstance(einfo.EntityName); pEntity.Id = Convert.ToInt64(pid); try { pEntity.GetType().GetProperty(einfo.Properties[0].FieldName).SetValue(pEntity, table.Rows[rIndex]["PTC"], null); objEntity.GetType().GetProperty("Parent" + einfo.EntityName).SetValue(objEntity, pEntity, null); } catch (Exception ex) { } return; }