Invoke explicitly implemented static interface method

Some native types have explicitly implemented methods from e.g. IParsable<TSelf> on them, how can I call these? For example, static char ISpanParsable<char>.Parse(ReadOnlySpan<char> s, IFormatProvider? provider) => ... in char: https://source.dot.net/#System.Private.CoreLib/src/libraries/System.Private.CoreLib/src/System/Char.cs,1948
2 Replies
ero
ero6d ago
i believe this is only possible through a generic parameter
T Parse<T>(ReadOnlySpan<char> s, IFormatProvider? provider)
where T : ISpanParsable<T>
{
return T.Parse(s, provider);
}
T Parse<T>(ReadOnlySpan<char> s, IFormatProvider? provider)
where T : ISpanParsable<T>
{
return T.Parse(s, provider);
}
Egil Hansen
Egil HansenOP6d ago
ill try it out looks like you are right, thanks.

Did you find this page helpful?