What would be the equivalent VB.NET code for this C# FluentNHibernate component mapping?

ⅰ亾dé卋堺 提交于 2019-12-01 18:40:42

In Visual Basic 2010 you can write the following

Component(Function(x) x.Address, Sub(m)
  m.Map(Function(x) x.Number)
  m.Map(Function(x) x.Street)
  m.Map(Function(x) x.PostCode)
  End Sub)

EDIT

Here is a VS2008 style solution. I'm not terrible familiar wit FluentNHibernate so I don't know what the type of M is but you should be able to replace MType with it's type and have the code work just fine.

Private Sub Helper(ByVal m As MType)
  m.Map(Function(x) x.Number)
  m.Map(Function(x) x.Street)
  m.Map(Function(x) x.PostCode)
End Sub

...  
Component(Function(x) x.Address, AddressOf Helper)

You are not able to do multiline lambda expressions in VB.Net. VB.Net 2010 will fix this I believe. Can you not just create a dll in C# and then call it from VB.Net?

Will, I share your frustration with the VB.NET implementation of lambdas as of the compiler for .NET 3.5/VS 2008. It really isn't so much that the language is poorly designed for lambdas, it is just that the implementation was incomplete with .NET 3.5. Lambda support involves a lot of compiler trickery that couldn't be completed in the timeframe required for the 2008 release. I want to point out that you can continue to target your current .NET framework version using VS 2010 and get the completed support for lambdas provided by the VS 2008 compiler. This means you can use multiline lambdas and anonymous Sub(to complete the previous existing anonymous Function), allowing Action <T> to work properly. You also can avoid the use of the underscore character for muitiline code statements. This is extremely convenient when working with lambdas directly, fluent APIs, or LINQ. Hopefully, this can help you make a strong argument to your client to upgrade your compiler version without introducing the risk of significant change. Aside from the very significant lack of support for iterator blocks, the VB.NET implementation in VS 2010 is pretty sweet as is the WPF-based Visual Studio itself! John Wigger

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!