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

发布于 2024-07-24 07:16:53 字数 215 浏览 2 评论 0原文

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

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

具有以下功能的东西 - 但我不知道到底是如何......

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

○愚か者の日 2024-07-31 07:16:53

它应该是这样的:

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

It should be something like this:

Dim s As String = blockRenderer.Capture(Function() RenderPartialExtensions.RenderPartial (h, userControl, viewData))
等风也等你 2024-07-31 07:16:53

在线查看此C# 到 VB.NET 转换器。 它并不总是让事情变得完美,但在我使用它的所有时候它都做得很好。

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

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))
毁梦 2024-07-31 07:16:53
Dim s As String = _
    blockRenderer.Capture( _
        Function() RenderPartialExtensions.RenderPartial(h, userControl, viewData) _
     )
Dim s As String = _
    blockRenderer.Capture( _
        Function() RenderPartialExtensions.RenderPartial(h, userControl, viewData) _
     )
一紙繁鸢 2024-07-31 07:16:53

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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文