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

ObjectExtensions - ToDataTable does not support string #77

Open
Aaron-Kibbie-ProgLeasing opened this issue May 19, 2022 · 1 comment
Open

Comments

@Aaron-Kibbie-ProgLeasing

Because a string is an IEnumerable of char when having a result of type string results in:
System.AggregateException : One or more errors occurred. (Sequence contains no elements)
----> System.InvalidOperationException : Sequence contains no elements
on the internal results variable

@Aaron-Kibbie-ProgLeasing
Copy link
Author

I can't create a branch/PR so here is the code change suggested:

static class ObjectExtensions
{
     internal static DataTable ToDataTable(this object result, Type resultType) =>
         (result is not string && result is IEnumerable results) ?
         results.ToDataTable(resultType.GenericTypeArguments.Single()) :
         new[] { result }.ToDataTable(resultType);
}

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