-
-
Notifications
You must be signed in to change notification settings - Fork 383
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
Anonymous object creation #75
Comments
For the same field works like this:
How to do this for multiple fields?:
For:
|
You are right, unfortunately for now anonymous object are not supported. I will think about this for a future release...any help is appreciated 😃 |
I had a look, and it seems quite difficult: the anonymous type has to be defined at runtime, and to do that, you need to add a custom dynamic assembly to the current app domain, and then add the new anonymous type to that custom assembly. Also, that custom assembly must be unloaded when it's no longer needed, to avoid memory bloat. Also, the anonymous type must define fields, properties, a default constructor, and possibly a Creating a dynamic assembly doesn't seem possible with netstandard 2.0, only with netstandard 2.1. I found a project that does most of it, except that it doesn't unload the dynamic assembly, and it's also not compatible with netstandard. https://github.com/dotlattice/LatticeUtils/blob/master/LatticeUtils/AnonymousTypeUtils.cs |
Thank you @metoule for the interesting analysis! I agree with your conclusion. For now let's keep the issue open. |
Another possibility, depending on the outcome desired for this, is to return an ExpandoObject. This would allow consuming code to be able to reference it as dynamic, or be passed to other interpreters since there is already some support for I do have a decent amount of experience in building classes at run time, especially for the simple classes that are created as anonymous types. Looking into how those are actually compiled out
ends up getting compiled out to a class as follows
|
how to get from:
string strExpression = "x => new { x.Ido, x.OtdName }";
such expression:
Expression<Func<T, object>> result = x => new {x.Ido, x.OtdName };
I need this to select specific fields in Generic Repository:
The text was updated successfully, but these errors were encountered: