How to best implement a property with a dynamic data type depending on the value of another property?
I have a class for an Order with two properties OrderType (enum) and OrderStatus (enum)
The problem is that the data type for OrderStatus is different depending on the value OrderType
public class Order
{
// Enums
public enum OrderTypes { Restaurant, Grocery, Wallet }
public enum RestaurantOrderStatus { OrderPlaced, Pending, Preparing, ReadyForPickup OnTheWay, Cancelled }
public enum GroceryOrderStatus { OrderPlaced, Enqueued, Preparing, OnTheWay, Cancelled, Returning }
public enum WalletOrderStatus { OrderPlaced, OnTheWay, Cancelled }
// Properties
public OrderTypes OrderType { get; set; }
public OrderStatuses OrderStatus { get; set; } // How to set a dynamic data type (different enum)?
public int Id { get; set; }
}
What is the best approach to do this?
Using Generic Type?
Using Builder Pattern?
I would implement a Generic Type.