C
C#2y ago
Vektor

✅ Multiple inheritance question

I have a partial class webform that is inheriting a base page class. Inside it there are multiple references to base methods. I am required to make a similar one with ever so slightly different functionality that has to be in a separate aspx. The question is can I use Multiple inheritance to avoid copy pasting the code over into the new one and making the changes? Is it possible to just inherit the partial and somehow access the base methods required for it to function?
7 Replies
sibber
sibber2y ago
c# doesnt support multiple inheritance thankfully its hard to recommend what to do in a case like this without seeing the code
Vektor
VektorOP2y ago
The gist of it is copy paste code but i am trying to find out if i can avoid copy pasting everything and doing it more elegantly. The new webform that will provide the service is 99% identical to the old but it has it's own unique flares and features in a sense. I can't make it inherit the old partial class which inherits the base since I don't think it will allow me to access the base methods right?
Tvde1
Tvde12y ago
You cannot make a class that inherits from two classes, but you can turn your existing form into a new 'base class' which contains the shared code, and make your two pages inherit from your base class it's possible for a class to inherit from a class, which itself inherits from a diffrent class possible:
class Page {}
abstract class FormBase : Page {}

class Page1 : FormBase {}
class Page2 : FormBase {}
class Page {}
abstract class FormBase : Page {}

class Page1 : FormBase {}
class Page2 : FormBase {}
not possible
class Page {}
class FormBase {}

class Page1 : FormBase, Page {}
class Page2 : FormBase, Page {}
class Page {}
class FormBase {}

class Page1 : FormBase, Page {}
class Page2 : FormBase, Page {}
Vektor
VektorOP2y ago
okay cheers for the explanation and the alexkneel to do it more elegantly i need to do a full refactor of the service which given the deadline of today is not possible for the release, for now copy pasta it is and future releases with the refactored version
Tvde1
Tvde12y ago
welcome to developer life!
Vektor
VektorOP2y ago
pain
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server