Map nested objects and records
masterExcelMapper supports mapping hierarchical data structures (parent/child objects) automatically. If your Excel columns follow a naming convention that matches your nested class properties, no extra configuration is required.
This support extends to C# records. For positional records without a default constructor, the mapper uses the constructor with the highest number of arguments, provided the parameter names match the property names (case-insensitive).
public class Person
{
public string Name { get; set; }
public Address Address { get; set; }
}
public class Address
{
public string Street { get; set; }
public string City { get; set; }
}
// Works with records too
public record Person(string Name, Address Address);
public record Address(string Street, string City);
var customers = new ExcelMapper("customers.xlsx").Fetch<Person>();