Proposal: Custom with
interface
#6538
Unanswered
RenderMichael
asked this question in
Language Ideas
Replies: 2 comments 5 replies
-
Error |
Beta Was this translation helpful? Give feedback.
0 replies
-
You should call the method DeepClone. |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Often times when I work with records (no pun intended), I want to use the
with
keyword but instead need a deep copy, leaving me to ditchwith
and write a custom Clone() method.I would love to see the following new API surface
And any record implementing this interface would have
IRecordCloneable<T>.Clone()
invoked instead of the record-generated<Clone>
method when using thewith
keyword.Since there's discussion on expanding the scope of
with
from being record-exclusive, the name could be altered so that's not locked in (ICustomWith
?).An alternative design would be to implement the old
ICloneable
interface, soso anyone implementing
ICloneable
isn't affected, but you can enablewith
functionality by simply replacing your oldCloneable
class withIRecordCloneable<self>
. The latter I'm sure is more controversial, but the core concept should be considered.Beta Was this translation helpful? Give feedback.
All reactions