I am trying to access all the properties of my derived class through base class reference variable.
Classes
public class vehicle
{
public int ID { get; set; }
}
public class Car : vehicle
{
public string type { get; set; }
public string Name { get; set; }
}
Here is the main in Main class
public static void saveCar<T>(T vehicle) where T : vehicle
{
//TODO : here I need to access all the propertie values but I dunno how access only derived class values
}
I am trying to do this way
static void Main(string[] args)
{
Car cr = new Car
{
ID = 1,
type = "car",
Name = "Maruthi"
};
saveCar<Car>(cr);
}
You can't really ask for T and know your real properties.
I think you should change your design to something like this: