I have a somewhat complex situation involving inheritance. I have a base DataObject
class that my Invoice
class inherits from. I want to save the Invoice
object using the DataObject
save method and then return the Invoice
object that was just saved.
public abstract class DataObject {
public virtual DataObject Save() {
// Save data
return this;
}
}
derived classes
public class InvoiceObject : DataObject {
// base data for the class goes here
}
public class Invoice : InvoiceObject {
public override DataObject Save() {
// Somehow return an Invoice object here
return base.Save();
}
}
I want to avoid using casts if possible. Any insight would be helpful. For arguments sake the structure must remain the same. I cannot remove the InvoiceObject
object and the Save
method must return the entire Invoice
object that was saved to the database. I am not even sure if this is possible, but I really hope it is.