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

Incorrect ToDynamicListAsync(this IEnumerable source, Type type) and ToDynamicArrayAsync(this IEnumerable source, Type type) behavior #327

Closed
GoNextGroup opened this issue Nov 25, 2019 · 4 comments
Labels

Comments

@GoNextGroup
Copy link

Hello.

I try to use IEnumerable.ToDynamicListAsync(Type type). So, it's not cast to my custom type (for example, I have problem with casting to strings).

I checked your code and possible found the reason of this unbehavior definition:

you have

        public static Task<List<dynamic>> ToDynamicListAsync([NotNull] this IEnumerable source, [NotNull] Type type)
        {
            Check.NotNull(source, nameof(source));
            Check.NotNull(type, nameof(type));

            return Task.Run(() => source.ToDynamicList());
        }

instead (possible) of

        public static Task<List<dynamic>> ToDynamicListAsync([NotNull] this IEnumerable source, [NotNull] Type type)
        {
            Check.NotNull(source, nameof(source));
            Check.NotNull(type, nameof(type));

            return Task.Run(() => **source.ToDynamicList(type));**
        }

This possible error was also found in ToDynamicArrayAsync([NotNull] this IEnumerable source, [NotNull] Type type)

@StefH StefH added the question label Nov 26, 2019
@StefH
Copy link
Collaborator

StefH commented Nov 26, 2019

When the object is a string, only then you can cast it to string!

Example:

var result = new List<string> { "x", "x2" }.ToDynamicList(typeof(string));

@StefH StefH closed this as completed Nov 26, 2019
@GoNextGroup
Copy link
Author

StefH, I know, I've just wanted to show that in your code you have problem only in async cast methods.

return Task.Run(() => source.ToDynamicList()); <--- this code do not make any casts to the asked type.

@StefH StefH reopened this Nov 29, 2019
@StefH
Copy link
Collaborator

StefH commented Nov 29, 2019

Ah I see. This needs to be fixed.

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

No branches or pull requests

2 participants