I had to do a code review for one of the business applications written in core C#. The framework includes entities and I see this pattern in all entity classes where an overloaded constructor takes the entity as a parameter. A simplified version of it looks like -
public class SomeEntity
{
public SomeEntity()
{
this.Name = string.Empty;
}
public SomeEntity(SomeEntity entity)
{
if (entity == null)
{
throw new System.ArgumentNullException("entity");
}
this.Name = entity.Name;
}
public string Name { get; set; }
}
Not sure if a code generator or template was used, but this is common across all entities and wondering if there is a pattern around it. I have never come across this kind of code and wondering if it makes sense.
Why would the same entity be a parameter of an overloaded constructor and how can this be used at all as the entity has to be created before it can be passed to the overload?