Inherit constructor #4641
Replies: 3 comments 2 replies
-
Unfortunately, the way that C# works today, if you require parameters to a constructor, every derived class must reimplement the constructor. I think that required properties (C# 10?) will solve this problem. |
Beta Was this translation helpful? Give feedback.
-
See: #806 |
Beta Was this translation helpful? Give feedback.
-
If you can use source generators in that project, this is something you could implement yourself and start using now rather than waiting many years for the language process (if the idea ever rises to priority). You could write a source generator that automatically adds constructors matching the base constructors to every class you declare. You could make it controllable using an attribute you define as internal if you prefer. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm trying to create a system close to Unity's with GameObjects and Components.
Component
is an abstract class with a constructor which requires a reference to a GameObject as a parameter.Everything is sound so far but now I've created useless boilerplate work for every single class that will ever inherit from Component. Now I have to explicitly create a constructor which takes in the arguments for the
base
class, regardless if I need a special constructor for the class.Why can't I have the 'inheriting' class inherit the constructor as well. Why do I have to write it out every single time.
If there's a work around I'd greatly appreciate a comment :)
Thanks for reading.
Beta Was this translation helpful? Give feedback.
All reactions