在 vb.net 中使用 nservicebus
我正在尝试将 nServiceBus PubSub .net4 示例转换为 vb,但我在某一时刻遇到了困难,我认为这是一个语言问题,但我想我应该询问专家。
有问题的代码来自发布者:
var eventMessage = publishIEvent ? Bus.CreateInstance<IEvent>() : new EventMessage();
当我尝试在 vb 中运行此代码时,
Public Property Bus As IBus
Dim eM As New EventMessage()
eM = Bus.CreateInstance(Of IEvent)()
我收到一个对象引用未设置为对象实例的错误
接口上使用 new
,但随后我收到一条错误消息,指出我不能在 iBus 为any 的 关于如何解决这个问题的想法?
考虑到 c# 和 vb.net 之间的相似之处,我不敢相信这是不可能的?
任何想
法谢谢克里斯
欢迎
Im trying to convert the nServiceBus PubSub .net4 example into vb and I'm struggling at one point which I think is a language issue but I thought I would ask the experts.
The code in question is from the publisher:
var eventMessage = publishIEvent ? Bus.CreateInstance<IEvent>() : new EventMessage();
When I try and run this in vb with
Public Property Bus As IBus
Dim eM As New EventMessage()
eM = Bus.CreateInstance(Of IEvent)()
I get a object refrence not set to an instance of the object error
But then I get an error saying I cant use new on an interface which iBus is
any ideas on how I get around this?
Given the similarities between c# and vb.net I cant believe this isnt possible?
Any ideas welcome
Thanks
Chris
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
条件的两个部分没有相同的类型,但它们都可以分配给
IEvent
(我相信),这是 C# 编译器将使eventMessage
具有的类型。试试这个:(可能不完全正确的语法;我的 VB 越来越生锈了...)
(顺便说一句,我建议使用名称
eventMessage
而不是eM
.)The two parts of the conditional do not have the same type, but they are both assignable to
IEvent
(I believe), which is the type the C# compiler will makeeventMessage
have. Try this:(probably not entirely correct syntax; my VB is getting rusty...)
(By the way, I'd suggest using the name
eventMessage
in stead ofeM
.)上面的 C# 代码是一个 if-then 结构。我面前没有代码,但该行本质上是以下内容的简写:
希望这有助于解决问题。
仅供参考,我意识到上面的代码在语法上不正确,只是试图说明 C# 语句的要点。
The C# code above is a if-then structure. I don't have the code in front of me, but the line is essentially shorthand for:
Hope this helps solve the issue.
FYI, I realize the code above is not syntactically correct, just trying to illustrate the point of the C# statement.