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

Add an overload to the "ToDynamicList" method which accepts a Type #48

Closed
rpaschoal opened this issue Oct 17, 2016 · 12 comments
Closed
Assignees
Labels

Comments

@rpaschoal
Copy link

rpaschoal commented Oct 17, 2016

Hello @StefH,

Is it possible to add a new overload to the existing "ToDynamicList" extension method which accepts an instance of a Type class in order to return a typed list?

This may also come as an enhancement to the library itself since most people use it for dynamic operations which they may only know the type of their data at runtime.

As a workaround for now I did the following which is a bit nasty but it is working:

var genericTypeArgument = resultProperty.GetType().GetTypeInfo().GenericTypeArguments[0];

var method = typeof(DynamicEnumerableExtensions).GetMethods().Where(x => x.Name == "ToDynamicList" && x.IsGenericMethod == true).First();

var dynamicQueriedResult = resultProperty.Where(filters);

resultProperty = method.MakeGenericMethod(genericTypeArgument).Invoke(dynamicQueriedResult, new object[] { dynamicQueriedResult});

Many Thanks!

@StefH StefH self-assigned this Oct 17, 2016
@StefH StefH added the feature label Oct 17, 2016
@StefH
Copy link
Collaborator

StefH commented Oct 17, 2016

You mean the a new extension method should be added like:

public static List<dynamic> ToDynamicList([NotNull] this IEnumerable source, [NotNull] Type type)

Which will generate a typed result list from Type type?

@rpaschoal
Copy link
Author

rpaschoal commented Oct 17, 2016

Yes @StefH! That is it!

What do you think about it? Possible, good idea?

For me that would be very useful!

Thanks :)

@StefH
Copy link
Collaborator

StefH commented Oct 19, 2016

Good idea, yes.
Possible, probably. However I'm not yet sure how to build this. Maybe reuse code from the Select() method?

@rpaschoal
Copy link
Author

You could also reuse the code I just posted above and make a call to the existing ones you have through reflection.

I could fork it and do it if you would like me to.

Cheers!

StefH added a commit that referenced this issue Oct 22, 2016
@StefH
Copy link
Collaborator

StefH commented Oct 22, 2016

Should be fixed. See new nuget.

@rpaschoal
Copy link
Author

@StefH,

Thanks for that! I will have a look as soon as possible.

Cheers!

@StefH
Copy link
Collaborator

StefH commented Nov 8, 2016

@rpaschoal Did you have time to take a look ?

@StefH
Copy link
Collaborator

StefH commented Nov 16, 2016

@rpaschoal Any update?

@rpaschoal
Copy link
Author

Hello @StefH,

I will have a look in a few days... I am currently enjoying some holidays!

Thanks :)

@StefH
Copy link
Collaborator

StefH commented Dec 17, 2016

@rpaschoal Any luck ?

@StefH
Copy link
Collaborator

StefH commented Dec 30, 2016

@rpaschoal Any update?

@StefH
Copy link
Collaborator

StefH commented Feb 5, 2017

Closing

@StefH StefH closed this as completed Feb 5, 2017
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