mardi 29 septembre 2015

Building a Composite from list - C#

I have an abstract base class,

Public absctact class BaseItem
{
  public BaseItem ParentItem { get; set; }

  // Some other Methods
}

I have some classes implementing this abstract class, the problem is I have to create a Composite class from a input list. Say I have a list of int's coming in a particular order, a list of length 5. I have to iterate this list and create a composite object of BaseItem which will go 5 level deep. In the first iteration create a concrete type of BaseItem, this will be the first item. In the next iteration create a concrete class and set this as the parentItem of the first item and so on and so forth. The resulting object of BaseItem type will be 5 level deep with the last parents parentItem as null.

Can someone help me with implementing this logic.

Aucun commentaire:

Enregistrer un commentaire