views:

457

answers:

4

What would this line of C# using Lambda expression be in VB.Net?

string s = blockRenderer.Capture(() => RenderPartialExtensions.RenderPartial(h, userControl, viewData));

Something with function of - but I can't figure out exactly how...

+4  A: 

It should be something like this:

Dim s As String = blockRenderer.Capture(Function() RenderPartialExtensions.RenderPartial (h, userControl, viewData))
Jason Heine
+3  A: 

Check out this online C# to VB.NET converter. It doesn't always get things perfect, but it does a pretty good job all the times I've used it.

Dim s As String = blockRenderer.Capture(Function() RenderPartialExtensions.RenderPartial(h, userControl, viewData))
Dennis Palmer
+1  A: 
Dim s As String = _
    blockRenderer.Capture( _
        Function() RenderPartialExtensions.RenderPartial(h, userControl, viewData) _
     )
Joel Coehoorn
+1  A: 

Lambda Expressions in VB.NET need to have a return value, the solution is a wrapper method.

Public Shared Function RenderPartialToString(ByVal userControl As String, ByVal viewData As Object, ByVal tempData As Object, ByVal controllerContext As ControllerContext) As String

        Dim h As New HtmlHelper(New ViewContext(controllerContext, New WebFormView("omg"), viewData, tempData), New ViewPage())
        Dim blockRenderer As New MvcContrib.UI.BlockRenderer(controllerContext.HttpContext)
        Dim s = blockRenderer.Capture(New Action(Function() renderPartialLambda(h, userControl, viewData)))

        Return s

End Function





Private Shared Function renderPartialLambda(ByVal html As HtmlHelper, ByVal userControl As String, ByVal viewData As Object)
                RenderPartialExtensions.RenderPartial(html, userControl, viewData)
                Return Nothing
End Function
marc.d