The task is to define with the least amount of code an immutable ValueObject with a large number of properties.
I use NHibernate as ORM , therefore properties should be virtual and public / protected . This object is mapped to a table from the database.
This object should not change, but it is necessary that it can be created.
If there are not many properties, then there are no problems, like this:
public class ElectricDevice { public virtual int Id { get; protected set; } public virtual string Name { get; protected set; } public virtual bool IsDecommissioned { get; protected set;} public ElectricDevice(int id, string name, bool isDecommissioned) { Id = id; Name = name; IsDecommissioned = isDecommissioned; } } But if there are a lot of properties, for example, 20, then it is somehow inconvenient to write a class for a long time (besides, there should be a lot of such classes). It is also not nice to create such an object through the constructor. Any ideas? Maybe in C # 6 any new syntax?
ElectricDevice electricDevice = new ElectricDeviceBuilder() { Id = id, Name = name, OtherProperty = otherValue }.Build();- VladD