C# Lambda 转换为 VB

发布于 2024-08-16 02:32:08 字数 934 浏览 2 评论 0原文

您好,我一直在查看有关 Sharparchitecture 的某些教程,但没有成功(在线转换器似乎无法做到这一点):

private Action<AutoMappingExpressions> GetSetup()
{
    return c =>
    {
        c.FindIdentity = type => type.Name == "Id";
    };
}

private Action<IConventionFinder> GetConventions()
{
    return c =>
    {
        c.Add<MVCTemp.Data.NHibernateMaps.Conventions.ForeignKeyConvention>();
        c.Add<MVCTemp.Data.NHibernateMaps.Conventions.HasManyConvention>();
        c.Add<MVCTemp.Data.NHibernateMaps.Conventions.HasManyToManyConvention>();
        c.Add<MVCTemp.Data.NHibernateMaps.Conventions.ManyToManyTableNameConvention>();
        c.Add<MVCTemp.Data.NHibernateMaps.Conventions.PrimaryKeyConvention>();
        c.Add<MVCTemp.Data.NHibernateMaps.Conventions.ReferenceConvention>();
        c.Add<MVCTemp.Data.NHibernateMaps.Conventions.TableNameConvention>();
    };
}

Hi I have been looking at certain tutorials on sharparchitecture and trying to no avail (the online convertors don't seem to be able to do this):

private Action<AutoMappingExpressions> GetSetup()
{
    return c =>
    {
        c.FindIdentity = type => type.Name == "Id";
    };
}

private Action<IConventionFinder> GetConventions()
{
    return c =>
    {
        c.Add<MVCTemp.Data.NHibernateMaps.Conventions.ForeignKeyConvention>();
        c.Add<MVCTemp.Data.NHibernateMaps.Conventions.HasManyConvention>();
        c.Add<MVCTemp.Data.NHibernateMaps.Conventions.HasManyToManyConvention>();
        c.Add<MVCTemp.Data.NHibernateMaps.Conventions.ManyToManyTableNameConvention>();
        c.Add<MVCTemp.Data.NHibernateMaps.Conventions.PrimaryKeyConvention>();
        c.Add<MVCTemp.Data.NHibernateMaps.Conventions.ReferenceConvention>();
        c.Add<MVCTemp.Data.NHibernateMaps.Conventions.TableNameConvention>();
    };
}

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

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

发布评论

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

评论(1

執念 2024-08-23 02:32:08

我假设您正在尝试将其转换为 VB.Net。

在 Visual Basic 2010 之前(当前为 测试版),这是不可能的。

VB.Net 2008 中的 Lambda 表达式只能保存单个表达式。

但是,您可以创建完成工作并返回它们的共享辅助函数。

例如:(在VB中)

Function GetConventions() As Action(Of IConventionFinder) 
    Return AddressOf GetConventionsHelper
End Function

Shared Sub GetConventionsHelper(c As IConventionFinder)
    c.Add(Of MVCTemp.Data.NHibernateMaps.Conventions.ForeignKeyConvention)()
    c.Add(Of MVCTemp.Data.NHibernateMaps.Conventions.HasManyConvention)()
    c.Add(Of MVCTemp.Data.NHibernateMaps.Conventions.HasManyToManyConvention)()
    c.Add(Of MVCTemp.Data.NHibernateMaps.Conventions.ManyToManyTableNameConvention)()
    c.Add(Of MVCTemp.Data.NHibernateMaps.Conventions.PrimaryKeyConvention)()
    c.Add(Of MVCTemp.Data.NHibernateMaps.Conventions.ReferenceConvention)()
    c.Add(Of MVCTemp.Data.NHibernateMaps.Conventions.TableNameConvention)()
End Sub

I assume that you're trying to convert this to VB.Net.

Until Visual Basic 2010 (currently in beta), it's not possible.

Lambda expressions in VB.Net 2008 can only hold a single expression.

However, you could create Shared helper functions that do the work and return them.

For example: (In VB)

Function GetConventions() As Action(Of IConventionFinder) 
    Return AddressOf GetConventionsHelper
End Function

Shared Sub GetConventionsHelper(c As IConventionFinder)
    c.Add(Of MVCTemp.Data.NHibernateMaps.Conventions.ForeignKeyConvention)()
    c.Add(Of MVCTemp.Data.NHibernateMaps.Conventions.HasManyConvention)()
    c.Add(Of MVCTemp.Data.NHibernateMaps.Conventions.HasManyToManyConvention)()
    c.Add(Of MVCTemp.Data.NHibernateMaps.Conventions.ManyToManyTableNameConvention)()
    c.Add(Of MVCTemp.Data.NHibernateMaps.Conventions.PrimaryKeyConvention)()
    c.Add(Of MVCTemp.Data.NHibernateMaps.Conventions.ReferenceConvention)()
    c.Add(Of MVCTemp.Data.NHibernateMaps.Conventions.TableNameConvention)()
End Sub
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文