Nullable approach with property defined in base and initialized in derived classes [Answered]
Is there an approach for the
Base.Some
property besides changing it to SomeType?
or suppressing with = null!;
. I want to defer the creation and leave it up to a derived class.
16 Replies
required
I think, did it land yet?Does that work in derived instances? 🤔
but you can just make a constructor honestly
I was thinking of just
required init;
since you set this property anyway
Constructor isn't good enough for the actual scenario. There's some logic involved.
ctor which takes in your SomeType instance
which you can generate with any logic
I can't use logic inside of the type's ctor to create the instance and pass the created instance to the parent ctor...I think.
should be able to I think 🤔
Oryp4ik#0120
REPL Result: Success
Compile: 479.328ms | Execution: 29.686ms | React with ❌ to remove this embed.
builds
That's a pretty simple expression, but it looks like
required
does the job.Good to hear. I have no experience with required, so couldn't help
Need to use
[SetsRequiredMembers]
on the ctor, too, if you don't want to use an object initializer.✅ This post has been marked as answered!