Once you have
public static TElement StringMatch<TElement, TData>(
this IEnumerable<TElement> source,
Func<TElement, TData> selector)
it covers the case where the caller passes a Func
where TData
is string
.
If you want TData
to always be the specific type string
then simply remove that as a formal generic parameter in the method:
public static TElement StringMatch<TElement>(
this IEnumerable<TElement> source,
Func<TElement, string> selector)
You can, of course, implement both. The compiler will select the most specific one. The caller can also specify the type parameters explicitly to leave only one choice.