mini-software / MiniExcel

Fast, Low-Memory, Easy Excel .NET helper to import/export/template spreadsheet (support Linux, Mac)
https://www.nuget.org/packages/MiniExcel/
Apache License 2.0
2.67k stars 327 forks source link

Type Query support multi parameter constructor and record #265

Open shps951023 opened 3 years ago

shps951023 commented 3 years ago

Like Dapper:

image

image

record image

shps951023 commented 3 years ago

MiniExcel :

CS0310 'UserQuery.MyClass' must be a non-abstract type with a public parameterless constructor in order to use it as parameter 'T' in the generic type or method 'MiniExcel.Query<T>(string, string, ExcelType, string, IConfiguration)'

image

image

record: image

shps951023 commented 3 years ago
public record MyUser(int Id, string FirstName, string LastName);

record will generate code like :

public class MyUser : IEquatable<MyUser>
{
    private readonly int _Id;
    private readonly string _FirstName;
    private readonly string _LastName;

    public int Id { get => _Id; init => _Id = value; }
    public string FirstName { get => _FirstName; init => _FirstName = value; }
    public string LastName { get => _LastName; init => _LastName = value; }

    public MyUser(int Id, string FirstName, string LastName)
    {
        _Id = Id;
        _FirstName = FirstName;
        _LastName = LastName;
    }
    //..
}