I am trying to create a generic class which new\'s up an instance of the generic type. As follows:
public class HomepageCarousel : List
There is another solution possible, rather dirty one.
Make IHomepageCarouselItem have "Construct" method which takes pageData as parameter and returns IHomepageCarouselItem.
Then do this:
T factoryDummy = new T();
List<T> carouselItems = new List<T>();
if (jewellerHomepages != null)
{
foreach (PageData pageData in jewellerHomepages)
{
T homepageMgmtCarouselItem = (T)factoryDummy.Construct(pageData);
carouselItems.Add(homepageMgmtCarouselItem);
}
}
return carouselItems;