I have a class called Location and it can either be Location<IClub> or Location<IRestaurant>.
I get a record from a database and that record then specifies whether this location is a restaurant or a club.
I need to create Location based on a string value within the record.
I have tried doing this;
object topLoc = null ;
if (record.type == "club")
topLoc = new Location<IClub>();
but I cannot access any of Location‘s properties.
I also can’t create the object in an if statement as when you leave the if the object will be out of scope.
It sounds like generics are not the tool you need. Rather than using generics to annotate the kind of location, consider using an
enum.