Kjensen
Kjensen

Reputation: 12384

Lambda expression from C# to VB.Net

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...

Upvotes: 1

Views: 2621

Answers (4)

marc.d
marc.d

Reputation: 3844

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

Upvotes: 1

Joel Coehoorn
Joel Coehoorn

Reputation: 416131

Dim s As String = _
    blockRenderer.Capture( _
        Function() RenderPartialExtensions.RenderPartial(h, userControl, viewData) _
     )

Upvotes: 1

CoderDennis
CoderDennis

Reputation: 13837

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))

Upvotes: 3

CodeLikeBeaker
CodeLikeBeaker

Reputation: 21312

It should be something like this:

Dim s As String = blockRenderer.Capture(Function() RenderPartialExtensions.RenderPartial (h, userControl, viewData))

Upvotes: 5

Related Questions