开发者

Very Specific C# to VB.NET Conversion Problem

开发者 https://www.devze.com 2023-01-24 02:52 出处:网络
I am currently working on a project which uses the AutoFac Inversion of Control container. I am attempting to convert some example code from C# into a codebase of an existing project of mine which is

I am currently working on a project which uses the AutoFac Inversion of Control container.

I am attempting to convert some example code from C# into a codebase of an existing project of mine which is written in VB.NET and I've hit a problem.

The original line of code is:

EventHub.Subscribe<HandshakingEvent>(container.Resolve<HandshakeAuthenticator>().CheckHandshake);

Which I have converted to:

EventHub.Subscribe(Of HandshakingEvent)(Container.Resolv开发者_运维百科e(Of HandshakeAuthenticator)().CheckHandshake)

But - this is causing an error, "Argument not specified for parameter 'ev' of CheckHandshake".

The type of the parameter for the EventHub.Subscribe(Of HandshakingEvent) procedure is System.Action (of HandshakingEvent)

I can see what the problem is, I'm just not really sure what to do about it! I've tried using 'AddressOf', but that doesn't seem to work, either.

Thanks in advance... - Chris


Try

EventHub.Subscribe(Of HandshakingEvent)(AddressOf Container.Resolve(Of HandshakeAuthenticator)().CheckHandshake)

(using the AddressOf keyword to get a delegate)


The VB code is trying to call the method instead of creating a delegate for it. Use the AddresOf operator to get a deletegate:

EventHub.Subscribe(Of HandshakingEvent)(AddressOf Container.Resolve(Of HandshakeAuthenticator)().CheckHandshake)

The keyword is not needed in C#, as parentheses are always used when you call a method, but in VB you can call a method without parentheses also.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号