Private primary constructors #8176
Unanswered
flakey-bit
asked this question in
Language Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Wondering whether we've considered the possibility of allowing primary constructors to be private. It might help with protecting invariants
For example, we have a type here that wants to protect the invariant that the GUID it wraps being not equal to
Guid.Empty
:At the call site:
If the primary constructor was private, we could enforce creation via the static factory, preserving the invariant.
NB: Not quite sure how this should behave for
record
typesBeta Was this translation helpful? Give feedback.
All reactions