I have a class Record
that works fine:
public class Record
{
protected string table;
protected string idcolumn;
public Record(string _table, string _idcol, int _id)
{
table = _table;
idcolumn = _idcol;
Id = _id;
}
}
I also have a class Order
that is derived from Record
, that implements extra methods, only applicable on a certain type of record:
class Order : Record
{
public void Start()
{
}
}
In my application, I have an object theRecord
of type Record
that I want to cast to Order
, so that I can call the Start
method on it.
I tried to cast it:
Order r = (Order)theRecord;
but that throws an InvalidCastException
.
I am thinking that I could create a new constructor for Order
that takes a Record
, but I already have the object (which is built by fetching a record from the database).
How could I implement this correctly?