Easy folder infinite level, using recursive refactoring hierarchy list

Source: Internet
Author: User


1 /// <summary>2 ///folder Entity3 /// </summary>4 Public classFolder5 {6 /// <summary>7 ///Folder ID8 /// </summary>9 Public intID {Get;Set; }Ten /// <summary> One ///folder name A /// </summary> - Public stringName {Get;Set; } - /// <summary> the ///Parent ID - /// </summary> - Public intfolder_parent_id {Get;Set; } -}
1         /// <summary>2         ///Refactoring the folder hierarchy list3         /// </summary>4         /// <param name= "Listsource" >Source Data</param>5         /// <param name= "PId" >Parent ID</param>6         /// <param name= "Count" >number of times the element was added</param>7         /// <param name= "Levelnum" >Current Level</param>8         /// <param name= "Listresult" >return result set</param>9         Private voidRefactorfolderlevellist (list<folder> Listsource,intPidintCount, list<int> Levelnum, list<folder>Listresult)Ten         { One             varLen_source =Listsource.count (); A             if(Count <Len_source) -             { -                 varTmp_list = listsource.where (m = m.folder_parent_id = =pId); the                 varLen_tmp_list =tmp_list. Count (); -                 BOOLAddflag =true; -                 intLevel =Levelnum.count (); -                 inti =0; +                 foreach(varIteminchtmp_list) -                 { +i++; AItem.name = Fillstring (level,"--") +Item.name; at                     varModel = Listresult.where (m = m.id = =item.id). FirstOrDefault (); -                     if(PId = =0&& Model! =NULL) -                         Continue; -                     Else - Listresult.add (item); -++count; in                     if(Listsource.where (m = m.folder_parent_id = = item.id). Count () >0) -                     { to                         if(!levelnum.contains (item.id) &&Addflag) +                         { -Addflag =false; the Levelnum.add (item.id); *                         } $ refactorfolderlevellist (Listsource, Item.id, Count, Levelnum, listresult);Panax Notoginseng                     } -                     Else the                     { +                         if(I <len_tmp_list) A                             Continue; theLevelnum =Newlist<int>(); +Refactorfolderlevellist (Listsource,0, Count, Levelnum, listresult); -                     } $                 } $             } -         } -         /// <summary> the         ///string padding -         /// </summary>Wuyi         /// <param name= "n" >number of fills</param> the         /// <param name= "str" >the string that needs to be populated</param> -         /// <returns></returns> Wu         Private stringFillstring (intNstringstr) -         { AboutStringBuilder ret =NewStringBuilder (); $              for(inti =0; I < n; i++) -             { - ret. Append (str); -             } A             returnret. ToString (); +}

Easy folder infinite level, using recursive refactoring hierarchy list

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.