Right now there's only an interface IDataBinder, but no class implementing it. Or better said: no class only implementing IDataBinder without also implementing IDataBinder<T>.
It seems that a lot of code inside CompiledDataBinder<T> could be modified to also bind data to an object of which we which we supply its Type.
I'd propose a class CompiledDataBinder, with a constructor like
CompiledDataBinder(
DataBinderOptions opts,
ReadOnlyCollection<DbColumn> physicalSchema,
Type recordType)
{
// ...
}
Why, you might ask? Since Sylvan.Data can also be used by Sylvan.Excel, I am interested in parsing multiple sheets into one object. That is, an object containing multiple lists, each list corresponding to one sheet. Given this functionality I can create a parsing strategy, something like this:
var tObject = new T();
do
{
var sheetName = edr.WorksheetName;
var type = MatchSheetNameWithType(sheetName);
if (type is null)
{
break; // Go to next sheet
}
var itemlist = new List<object>();
var binder = DataBinder.Create(edr, dataBinderOptions, type);
while (edr.Read())
{
var item = CreateInstanceOfType(type);
binder.Bind(edr, item);
itemList.Add(item);
}
AssignList(tObject, sheetName, itemList);
} while (edr.NextResult()); // NextResult goes to next sheet
I am willing to create a PR for this if you are also interested in this idea. If you know an easier way to achieve my goals, also please let me know 😄
Right now there's only an interface
IDataBinder, but no class implementing it. Or better said: no class only implementingIDataBinderwithout also implementingIDataBinder<T>.It seems that a lot of code inside
CompiledDataBinder<T>could be modified to also bind data to an object of which we which we supply itsType.I'd propose a class
CompiledDataBinder, with a constructor likeWhy, you might ask? Since
Sylvan.Datacan also be used bySylvan.Excel, I am interested in parsing multiple sheets into one object. That is, an object containing multiple lists, each list corresponding to one sheet. Given this functionality I can create a parsing strategy, something like this:I am willing to create a PR for this if you are also interested in this idea. If you know an easier way to achieve my goals, also please let me know 😄