I am trying to create an extension method that returns IEqualityComparer based on the lambda function. Heres the extension method:
<Extension()> Public Function Comparer(Of T)(Func As Func(Of T, T, Boolean)) As IEqualityComparer(Of T) Return New GenericComparer(Of T)(Func) End Function
Here is the use I'm looking for
Dim CICF = (Function(a As String, b As String) As Boolean If a.ToUpper = b.ToUpper Then Return True Else Return False End If End Function).Comparer
The compiler reports an error
'Comparer' is not a member of '<anonymous method>'
If I assign a function to an explicitly typed variable, it will work like this:
Dim CICF As Func(Of String, String, Boolean) = (Function(a As String, b As String) As Boolean If a.ToUpper = b.ToUpper Then Return True Else Return False End If End Function) Dim CIC = CICF.Comparer
So my questions are: can I type the extension method in such a way that I can use the single-line style I'm looking for? That is, how can I introduce an extension method to accept an anonymous method?
Kratz source share