Inheritance in classes generated from page types

S1T2 Developer asked on October 24, 2019 10:00

In order to allow different child page types, I've a few page types inheriting fields from a base page type. With classes generated via page types > code, this inheritance is, however, not carried into the classes.

For example, ContactPage and HomePage inherits all fields of Page, but all of them inherit TreeNode in the generated classes. As a result, they cannot share one view model even though all fields are common across the three.

My question is, what is the best way, WITHOUT modifying the generated classes, to have a common view model for the child classes?

Correct Answer

Dmitry Bastron answered on October 24, 2019 13:31

Hi,

Without modifying these classes it's not possible. Full stop. I would recommend instead of class inheritance look at interfaces: you can have interface IPage and in your ContactPage and HomePage model partials just assign this interface and deal with interfaces then.

0 votesVote for this answer Unmark Correct answer

   Please, sign in to be able to submit a new answer.