✅ Override (abstract) getter-only property with a setter
Hello! I was wondering if there is anyway to add a setter to an overridden getter-only property?
Currently, I've tried the following:
I'd prefer avoiding a constructor, since the rest of my hierarchy uses
required
properties, and Derived
is actually sub-classed elsewhere, so adding a constructor would make things a bit clunky...8 Replies
Why not make the count in base a method?
therefore it's only get, and you can customize the value as much as you want in the future
As in
GetCount()
and then declarating a Count
prop for Derived? I mean that's what i'm doing in the meantime, but it's pretty clunkyperhaps protected set?
And also, consumers for
Derived
might be confused as to why there's both a Count
prop and a GetCount()
methodit would still be able to by set by classes that shouldn't set it but
🤔 didn't think about that, why not
yeah it's not perfect, but it's less clunky than a method, and they're internal classes so eh 🤷♀️
You could make the set within the base class throw an error
at best
yepyep probably what i'm gonna do
thank you for the help :)