You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Doesn't seem to work with generic extension methods #21
In my project I have a generic interface implemented by a few entity classes, and a generic extension method for that interface. When I tried using Expressionify on that method, the generator does come up with a static expression, but the type of it contains the method's generic parameter which is undefined in this context and causes compiling error.
I think in order to support generic methods, the generator will also have to output a generic static method (that returns the lambda expression) instead of a static property. For a given set of generic parameter assignment, the expression visitor will invoke the method for the first time, and the returned lambda expression can then be cached in a dictionary mapping sets of generic parameter assignments to the returned expressions.
Thats a very creative way of solving identifying the source expression types. What about if you simply generate the constraint types in the extension methods?
Replacing with the contraint type might work in some cases, but I don't think it will work in general. For example, if the returned type of the expression also involves the generic parameter, such a replacement could make the result too general for whoever is using the expression.
In this case replaceing T with its constraint (none in this case, so it will simply be object) will result in the extension method returning just an object instead of a T, and thus runtime error will occur if other part of the expression tries to access anything specific about T on the returned result.
@mariusGundersen Still not working. It still shows an error message saying that "cannot find the type or namespace of [name of the generic parameter]" (paraphrased). It seems that the generated .g.cs file is immediately deleted afterwards so I have no idea what code was being generated.
Activity
MuTsunTsai commentedon Nov 5, 2022
I think in order to support generic methods, the generator will also have to output a generic static method (that returns the lambda expression) instead of a static property. For a given set of generic parameter assignment, the expression visitor will invoke the method for the first time, and the returned lambda expression can then be cached in a dictionary mapping sets of generic parameter assignments to the returned expressions.
jeffward01 commentedon Dec 11, 2022
Thats a very creative way of solving identifying the source expression types. What about if you simply generate the constraint types in the extension methods?
I will test this with Expressionfy, but I think that this might be the outcome: EFNext/EntityFrameworkCore.Projectables#54 (comment)
MuTsunTsai commentedon Dec 12, 2022
Replacing with the contraint type might work in some cases, but I don't think it will work in general. For example, if the returned type of the expression also involves the generic parameter, such a replacement could make the result too general for whoever is using the expression.
mariusGundersen commentedon Dec 12, 2022
Can you show an example of what you mean? How would it be too general?
MuTsunTsai commentedon Dec 14, 2022
@mariusGundersen Consider something as simple as
In this case replaceing
Twith its constraint (none in this case, so it will simply beobject) will result in the extension method returning just anobjectinstead of aT, and thus runtime error will occur if other part of the expression tries to access anything specific aboutTon the returned result.mariusGundersen commentedon Dec 14, 2022
I am working on a version that supports generics. Can you try with pre-release version 6.7.0-generics.41?
MuTsunTsai commentedon Dec 20, 2022
@mariusGundersen Still not working. It still shows an error message saying that "cannot find the type or namespace of [name of the generic parameter]" (paraphrased). It seems that the generated .g.cs file is immediately deleted afterwards so I have no idea what code was being generated.