The real problem comes up with Reflection and assembly patching/hooking. I'll put a simple example to show up my question without being too hard to understand the main problem.
So let's imagine I have these basic classes :
public class Vehicle
{
public string Name;
public string Price;
public void DoSomething()
{
Main.Test(this);
}
}
public class Car : Vehicle
{
public int Wheels;
public int Doors;
}
And on the main code I run this up :
public class Main
{
public void Start()
{
Car testCar = new Car()
{
Name = "Test Car",
Price = "4000",
Wheels = 4,
Doors = 4
};
testCar.DoSomething();
}
public static void Test(Vehicle test)
{
// Is this allowed ?
Car helloWorld = (Car) test;
}
}
Okay, the question is :
Is that cast allowed (in the static method Test) ? Will I lose the Car properties but keep the Vehicle ones ?
In case it's wrong, is there any other way to do it ?
Thanks.