Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Make RowInfo<TTarget> Inherit from TTarget for Easier Data Access #149

Open
base553 opened this issue Mar 6, 2025 · 0 comments

Comments

@base553
Copy link

base553 commented Mar 6, 2025

Currently, RowInfo is a separate class that wraps metadata about a row (e.g., row index, column mappings) along with a reference to the Target object of type TTarget. While this design works well for accessing metadata, it requires additional steps to directly access or manipulate properties of TTarget itself. For example, when working with asynchronous operations (e.g., Task), developers need to unwrap the Target property explicitly, which adds complexity.

I propose that RowInfo should inherit from TTarget directly. This would allow RowInfo to expose all properties and methods of TTarget without needing to access the Target property separately. Additionally, this would make it more convenient to work with asynchronous data (e.g., Task), as the object could be used directly in a more fluent manner.

Use Case:

Consider a scenario where I’m mapping Excel rows to a Person class asynchronously:

public class Person
{
    public string Name { get; set; }
    public int Age { get; set; }
}

async Task ProcessRowsAsync()
{
    var mapper = new Mapper("file.xlsx");
    var rows = mapper.Take<Person>("Sheet1");
    foreach (var row in rows)
    {
        // Current: Need to access row.Value.Target explicitly
        Person person = row.Value;
        Console.WriteLine(person.Name);
    }
}

If RowInfo inherited from Person, I could simplify this to:

async Task ProcessRowsAsync()
{
    var mapper = new Mapper("file.xlsx");
    var rows = mapper.Take<Person>("Sheet1");
    foreach (var row in rows)
    {
        // Proposed: Direct access to Person properties
        Console.WriteLine(row.Name);
    }
}

This would also streamline working with Task<RowInfo> in asynchronous workflows, as the row object would directly expose Person properties.

Benefits:

Simplified access to TTarget properties without needing to drill into Target.
Improved ergonomics when working with asynchronous operations or LINQ queries.
More intuitive API for developers familiar with inheritance-based designs.
Potential Challenges:

Backward compatibility: Existing code relying on RowInfo as a wrapper might need adjustments.
Design consistency: Inheritance might introduce complexity if RowInfo needs to maintain its own state (e.g., row index) separate from TTarget.

Suggested Implementation:

Modify RowInfo as follows:


public class RowInfo<TTarget> : TTarget where TTarget : class, new()
{
    public int RowIndex { get; set; }
    // Other existing properties/methods of RowInfo
}

This would allow RowInfo to inherit all properties of TTarget while retaining its metadata functionality.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant