title: Getting an object's list from inside another object
body: <p>This is the layout</p>
  
  <pre><code>     House -&gt; HouseDef -&gt; Room -&gt; Door
                              L---&gt; Windows
  </code></pre>
  
  <p>The problem is that any class may or may not have lists and nested classes like HouseDefinition does. The point is it should be flexible to handle any of these three cases for class variations: 
  1. hasList, 
  2. hasNestedObject with List inside that Nested Object
  3. Has neither a List nor Nested class</p>
  
  <p>Example of 1 being a Room class which contains a Window List
  Example of 2 like House Class
  Example of 3 like a Window Class</p>
  
  <p>I have these two classes that I want to access generically from another class. I want to be able to get the Rooms List in House Definition by access of House class stored as an object in MyTreeNode. How can I do this not bound by types, or polymorphic to support a deeper hierarchy level in the future?</p>
  
  <pre><code>public class House
  {
     string name;
     HouseDefinition definition;
  
     public string Name() { return name; }
     public HouseDefinition Definition {get {return definition;}}
  
  
     public House(string name,HouseDefinition definition)
     {
         this.name = name;
         this.definition = definition;
     }
  }
  
  public class HouseDefinition
  {
      private List&lt;Room&gt; rooms = new List&lt;Room&gt;();
      string type;
  
      public List&lt;Room&gt; Rooms { get { return rooms; } }
      public Room this[int i] { get { return rooms[i]; } }
      public HouseDefinition(string type)
      {
          DefaultLayout();
          this.type = type;
      }
  }
  
      public class MyTreeNode : TreeNode
      {
          string label;
          IEnumerable items;
          bool hasList;
          object item;
  
          public string Label { get {return label; } }
          public IEnumerable Items { get { return items;} }
          public object Item { get { return item; } }
  
          public bool HasList { get { return hasList; } }
  
          public MyTreeNode(object item)
          {
              this.item = item;
              label = item.ToString();
              hasList = false;
          }
          public MyTreeNode(object item, IEnumerable Items)
          {
              this.item = item;
              label = item.ToString();
              hasList = true;
  
          }
      }
  </code></pre>