❔ Custom Copy Semantics for `record struct`?
Hey all - I'm having a hard time figuring out how to (and if it's even supportedt) to do custom copy semantics for record structs. Changing my record type to a record/record class properly calls the copy ctor, but if it's a record struct, when I use
with
the copy ctor isn't being called. Would love any help here8 Replies
If you have a record struct
r
, with
just does
So it doesn't call a constructor or method, it just copies the entire struct memory on the stack.so this doesn't apply to record structs? https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/with-expression#custom-copy-semantics
with expression - create new objects that are modified copies of ex...
Learn about a with expression that performs nondestructive mutation of C# records and structures. The
with
keyword provides the means to modify one or more properties in the new object.Not according to Sharplab at least
this feels like an annoying oversight lol
Ask in #roslyn if you feel like it
thanks for the confirmation and help though @🌈 Thinker 🌈
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.