code_junkie

Implementing a tree in c# managing parent-child

Nov 13th, 2011
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. public class Folder
  2. {
  3. //Various Props like Name etc.
  4. public IList<Folder> Children{get;}
  5. public Folder Parent {get;}
  6. }
  7.  
  8. List<Folder> children;
  9.  
  10. public ReadOnlyCollection<Folder> Children
  11. {
  12. get { return this.children.AsReadOnly(); }
  13. }
  14.  
  15. IList<Folder> children;
  16.  
  17. public ReadOnlyCollection<Folder> Children
  18. {
  19. get
  20. {
  21. return new List<Folder>(this.children).AsReadOnly();
  22. }
  23. }
  24.  
  25. public class ChildCollection
  26. {
  27. // _Children is maintained by the Folder class, hence the internal access specifier
  28. internal Dictionary<KeyType, Folder> _Children = new Dictionary<KeyType, Folder>;
  29.  
  30. public this[KeyType key]
  31. {
  32. get
  33. {
  34. return _Children[key];
  35. }
  36. }
  37.  
  38. public IEnumerable<KeyType> Keys
  39. {
  40. get
  41. {
  42. return _Children.Keys;
  43. }
  44. }
  45. }
  46.  
  47. public IEnumerable<Folder> Children
  48. {
  49. get { return this.children.GetEnumerator(); }
  50. }
Add Comment
Please, Sign In to add comment