Is there an existing issue for this?
Describe the bug
Example class:
public class MyTryParsableParam : IParsable<MyTryParsableParam>
{
static bool IParsable<MyTryParsableArg>.TryParse([NotNullWhen(true)] string? s, IFormatProvider? provider, [MaybeNullWhen(false)] out AddsCustomParameterMetadata result)
{
result = new();
return true;
}
static MyTryParsableParam IParsable<MyTryParsableParam>.Parse(string s, IFormatProvider? provider) => throw new NotSupportedException();
}
Expected Behavior
ParameterBindingMethodCache should find the implicitly defined TryParse method and use it in RequestDelegateFactory and MVC's ModelMetadata.
Steps To Reproduce
It throws an exception that no matching method is found (despite finding it when generating the exception message :D)
Exceptions (if any)
System.InvalidOperationException : TryParse method found on AddsCustomParameterMetadata with incorrect format. Must be a static method with format
bool TryParse(string, IFormatProvider, out AddsCustomParameterMetadata)
bool TryParse(string, out AddsCustomParameterMetadata)
but found
static Boolean TryParse(System.String, System.IFormatProvider, AddsCustomParameterMetadata ByRef)
.NET Version
main branch
Anything else?
We could special-case IParsable because we have a reference to it. The check for !method.IsAbstract in GetStaticMethodFromHierarchy stops us from finding it now. But even if we did find it, we haven't implemented the correct code gen to call it for unreferenced interfaces. We might have to use Type.GetInterfaceMap. See previous discussion: #40926 (comment)
Is there an existing issue for this?
Describe the bug
Example class:
Expected Behavior
ParameterBindingMethodCache should find the implicitly defined TryParse method and use it in RequestDelegateFactory and MVC's ModelMetadata.
Steps To Reproduce
It throws an exception that no matching method is found (despite finding it when generating the exception message :D)
Exceptions (if any)
.NET Version
main branch
Anything else?
We could special-case IParsable because we have a reference to it. The check for
!method.IsAbstractin GetStaticMethodFromHierarchy stops us from finding it now. But even if we did find it, we haven't implemented the correct code gen to call it for unreferenced interfaces. We might have to use Type.GetInterfaceMap. See previous discussion: #40926 (comment)