从C#到VB.Net的Lambda表达式

时间:2009-06-11 14:59:04

标签: c# vb.net lambda

使用Lambda表达式的这一行C#在VB.Net中会是什么?

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

具有功能的东西 - 但我无法确切知道如何......

4 个答案:

答案 0 :(得分:5)

它应该是这样的:

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

答案 1 :(得分:3)

在线查看此C# to VB.NET converter。它并不总是让事情变得完美,但是在我使用它的过程中它确实做得很好。

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

答案 2 :(得分:1)

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

答案 3 :(得分:1)

VB.NET中的Lambda表达式需要有一个返回值,解决方案是一个包装器方法。

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