Replies: 2 comments 1 reply
-
The official response from the LDT is to 1) decorate the ctor with |
Beta Was this translation helpful? Give feedback.
-
Argh. I really like having the strictness of a compiler error, but I want to be able to specify base properties in descendant types (for things like defining more specific versions of general things). We do this now with records using primary constructors (where I can specify values for base properties), but I vastly prefer object initializers to constructor calls wherever possible. It sounds like I'm just SOL on this. How disappointing. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Here's the sort of thing I'd like to be able to write:
But I can't do that, because the instantiation of
Derived
still wantsBaseThing
set in the object initializer. I know I can use[SetsRequiredMembers]
on the constructors, but then I lose the compiler warning ifDerivedThing
isn't set in the object initializer. Is there a way to effectively narrow the list of required fields in descendant types? I vastly prefer using object initializers, so I was really looking forward to being able to use therequired
keyword, but when we updated to 8 (we only use LTS releases, so I didn't try this on 7), I ran into this problem.Beta Was this translation helpful? Give feedback.
All reactions