I have a base record type and an inherited record type which adds a few fields.
At runtime I have an instance of the base record type and want to convert it to an instance of the inherited record type, without retyping all the parameters.
I tried the following:
public record BaseRecord(string firstName, string lastName);
public record ChildRecord(BaseRecord baseRecord, DateTime dateOfBirth) : BaseRecord(baseRecord);
Now I can do the following:
var baseRecord = new BaseRecord("John", "Doe");
var childRecord = new ChildRecord(baseRecord, new DateTime(2000, 1, 1));
But unfortunately the ChildRecord now has a property “baseRecord” of Type BaseRecord, although it is delegated to the base constructor what normaly has the effect that its omitted and not added as a property to the record (at least I thought)
Is there any way to prevent the creation of the “baseRecord” property?
I don’t want to write all the fields as in C# create derived record from base record instance