-
-
Notifications
You must be signed in to change notification settings - Fork 11
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
Provide examples of Info.OfMethod for generic method and methods with arguments. #582
Comments
That double backquote in the documentation seems off, can you try with a single backquote instead? Also, the |
@ltrzesniewski, didn't work with single backtick either. |
see sample here: https://github.com/Fody/InfoOf/blob/master/Tests/ParamCheckerTests/GenericMethod.cs |
@virzak I've updated the readme, did this answer your questions? |
Thanks, the questions are answered. A few thoughts:
public int Produce<T>(T? t) where T : class => throw new NotImplementedException();
public int Produce<T>(T? t) where T : struct => throw new NotImplementedException();
|
Another thought on this topic. class MyClass
{
[CreateMethodInfo(location = "MyNS.MyOtherClass.ExistingField")]
public int Produce<T>(T? t) where T : class => throw new NotImplementedException();
[CreateMethodInfo(location = "MyNS.MyOtherClass.NonExistingField")] // will be added
public int Produce<T>(T? t) where T : struct => throw new NotImplementedException();
}
class MyOtherClass
{
static MethodInfo ExistingField = null! // will be overwritten
} |
I suppose that's a missing feature if it's not achievable today.
That's actually not possible to get in C#, even if it seems so. 🙂 Here are the actual signatures of your example methods: public int Produce<T>(T t) where T : class
public int Produce<T>(System.Nullable<T> t) where T : struct Removing the
That would be quite a bit of additional work, and would only be useful for symbols in your own assembly. If InfoOf isn't currently sufficient for your needs (and you really want those two method handles), I may suggest using my InlineIL weaver along with the ldtoken opcode, although that may prove a bit overkill. 😅 |
In your sample code above both methods are distinguishable by their parameters, so you can get them via InfoOf.Method<Class>("Produce", "T")
InfoOf.Method<Class>("Produce", "Nullable<T>") or to make it even more obvious, rename T to TClass and TStruct.
I think it's a very special edge case where you have a generic overload and the generic parameter is not used in the method parameters, so I wonder if it's worth spending efforts on this. Also I don't see the benefit of designing such an highly optimized code - and then accessing it via reflection? |
@tom-englert, you're probably correct. This is all about EF Core expression trees detecting that a certain method has been called. This not likely where the performance bottleneck will be, since EF Core itself pays a heavy cost upfront to generate queries. |
Describe the issue
Info.MethodOf
documentation is somewhat unclear regarding generic methods and parameters.Below are some of my attempts that came up short.
Minimal Repro
The text was updated successfully, but these errors were encountered: