I have an extension method like this:
<Extension()>
Public Function Trim(value As Object, MaxLength As Integer) As String
If value IsNot Nothing AndAlso value.ToString.Length > MaxLength Then
Return value.ToString.Substring(0, MaxLength)
Else
Return value.ToString
End If
End Function
My assumption was that I could then go Eval("MyColumnName").Trim(20) when databinding (Rather then doing things like MyMethod(Eval(“MyColumnName”)) but this has proved incorrect.
Is there any way to use extension on the Eval method?
PS: I have my extensions referenced as a global reference
It turns out that while you can extend the
Objecttype, you can’t use a variable of typeObjectto call the method.MSDN Magazine: Basic Instincts: Extension Methods
So I think the best you could hope for in a one-liner is: