Lets say I wish to be able to render different view logic for two different types, both are store items/products that will be used in search result views etc. Ultimately I would want the objects ordered according to a price property which both have, but of course they are still different types so I wonder if it is possible to order different object types in a list by using a property value of the same type on each?
I have a Product type and ProductCombo type.
Is it more optimal to store them in the model class as such (Probably can’t order them then):
public class
{
public List<Product> ProductList {get; set;}
public List<ProductCombo> ProductComboList {get; set;}
}
Or
public class
{
public List<object> StoreItems {get; set;}
}
If I use the above 2nd option I would of course have to unbox each object, get the type and decide what action to take for said type in the view. I think this is my best choice ? Considering that I would want to order the items in the List<object> by their decimal type price property.
Also another crude way to do it would be this I am guessing.
public class StoreItem
{
public Product product {get; set;}
public ProductCombo productCombo {get; set;}
public double itemPrice {get; set;}
}
And then just store in List<StoreItem>
setting the itemPrice when doing a foreach on
each object returned from the database.
Why not do something like this