How do I build a single function with which I can convert a nested List to a nested object[] array effectively?
p.s. the depth of the nested List varies.
for example:
public class ProductBindingViewSC
{
public int ProductID { get; set; }
public string aName { get; set; }
public List<Product_SuperType_Info> SuperTypeList { get; set; }
public List<Product_Image_Info> Product_ImageList { get; set; }
public List<Product_Property_BindingViewSC> Property1 { get; set; }
}
Property1 has structure like ProductBindingViewSC ( it has fields and List)
I need to do the following with only a few lines
List<ProductBindingViewSC> productList = new GetProductObject().getProductBySomeCondition( 123 );
var productArray = SomeFunction(productList );
or
ProductBindingViewSC product = new GetProductObject().getProductById( 345 );
var product = SomeFunction(product );
ProductArray has the exact same structure as ProductBindingViewSC but all the List Type are Array Type instead.
And if one of the object in List is empty, the array class will have one record of empty object in the Array .
EDIT:
Question : how should I write the SomeFunction. I can only think of looping with very ineffecient way and mine is not generic. I need a function which I can throw in any object type.