You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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:
If RowInfo inherited from Person, I could simplify this to:
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:
This would allow RowInfo to inherit all properties of TTarget while retaining its metadata functionality.
The text was updated successfully, but these errors were encountered: