Why do we have IsConstructedGenericType but not IsConstructedGenericMethod?
Proposal for New API:
class MethodBase
{
public virtual bool IsConstructedGenericMethod => IsGenericMethod && !IsGenericMethodDefinition;
}
This is both for completeness (Type has IsConstructedGenericType) and for better expressibility when testing if a MethodBase represents a method instantation.
Right now, the only way to perform that task is through this eyesore:
if (method.IsGenericMethod && !method.IsGenericMethodDefinition) {...}
This is wordy, requires two calls and requires the use of the 1.0-era IsGenericMethod (whose very use I consider to be a code smell due to its poor conceptual grasp of the distinction between generic methods and their instantiations.)
The proposed implementation allows the new api to give the correct result for 3rd party Reflection providers without any additional work on their part. Declaring it "virtual" (like its IsConstructedGenericType counterpart) makes it possible for providers to override with a more performant version (CoreRT is certainly well positioned to do this.)
Makes sense and looks good as proposed.
Adding it to CoreRt now.
CoreClr and CoreFx can be considered up for grabs, for at least the next few days.
@AtsushiKan in that case please mark it as "up for grabs" ;-) (I did it this time) And when you work on it / grab it, please assign it to yourself ...
IsConstructedGenericMethod now lit up on CoreClr (as part of https://github.com/dotnet/coreclr/pull/10202)
All that's left to do is to add it the contract and tests on corefx.
This should be fairly straightforward and somewhat fun with generics - see example of exposing API in dotnet/corefx#16996
Hi, I'd like to help resolve this issue seeing as it's up for grabs.
I've created a commit with the change as I've understood it.
- suggested API in MethodBase
- extended the MethodBaseTests of System.Runtime.Tests.
I'm not sure about the test coverage though.
I think I'm supposed to replace the MethodBase.IsConstructedGenericMethod implementation in ref project with an throw null, if I understand the ref project correctly. I believe the same throw null is needed in MethodBuilder in System.Reflection.Emit Could someone please confirm this?
I also see that the IsConstructedGenericMethod of TypeBuilder is not tested in System.Reflection.Emit tests. Should the IsConstructedGenericMethod of MethodBuilder be tested or should I omit the tests as it is omitted in TypeBuilder tests?
Thanks for contribution @DawidTabak! I sent you contributor invitation, so that we can assign this issue to you (GitHub limitation). Please ping me here when you accept the invitation.
Let's move the technical discussion to your PR.
Also note that we are finishing .NET Core 2.0 -- we will delay any new APIs and larger changes which are not critical for 2.0 until after May 10 (1.5 weeks). Just setting the expectation ... see https://github.com/dotnet/corefx/issues/17619#issuecomment-296872132 for details
Saw you accept @DawidTabak, assigning to you ...
@DawidTabak we got the okay to submit this API for 2.0 if we get a PR up in the next 2 or 3 days. If you can't manage that, it's okay, it will just miss 2.0. :)
@AtsushiKan, So if I declare a method void Foo<T, V>() and then using MakeGenericMethod to create a method void Foo<T, int>() the MethodInfo for the latter will return true for IsConstructedGenericMethod even though it cannot be invoked? If so, what does it buy me to know a method is IsConstructedGenericMethod?
If you're looking to discover if a method has open types that need further specialization, the api you're looking for is MethodBase.ContainsGenericParameters