© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
20 replies
Loup&Snoop

✅ Immutable object with mutable clone

I have a class EntityData which is full of fields that need to be read only (everything public get, private set).

I want to be able to make a different object that is a mutable clone, which behaves like EntityData in every way except every property is public.

During runtime, I will have multiple instances of a class (EntityDataHolder) which will get fed an immutable original EntityData, and then make a mutable clone so that this particular instance of EntityDataHolder can modify it freely.

I will later add more fields to EntityData, and I don’t want its definition and its clone’s definition to get messed up/misaligned (ie I want to avoid writing every field 4 times to make one on the original, clone, and clone-copying class all match up).

What is a clean way to do this?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Updating Immutable object with ef
C#CC# / help
2y ago
Entity DB object with immutable variables
C#CC# / help
2y ago
Clone
C#CC# / help
2y ago
clone
C#CC# / help
3y ago