将包含 NSubstitute 代码的 C# 语句转换为 VB.net [英] Convert C# statements including NSubstitute code to VB.net
问题描述
在阅读 NSubstitute 教程时,我将用 C# 编写的示例转换为 VB.net 以了解功能,但我需要您对这些(不相关的)语句的支持,尽管采取了所有措施,但我无法转换:>
1.
calculator().Received().Add(1, Arg.Is(Of Integer)(function(x) new[] {-2,-5,-10}.Contains(x)))
2.
注意:foo 是一个接口的派生对象,它有一个名为SayHello"的 void 方法
foo.When(x >= x.SayHello("World")).Do(x => counter++);
3.
calculator().When(x >= x.Add(-2, -2)).Do(x => { throw new Exception(); });
注意:引擎是从这个接口派生的对象:
公共接口 IEngine {事件 EventHandler 空闲;event EventHandler低燃油警告;事件 ActionRevvedAt;}
4.
engine.Idling += (sender, args) =>wasCalled = true;
5.
engine.Idling += Raise.EventWith(new object(), new EventArgs());
6.
engine.RevvedAt += rpm =>revvedAt = rpm;
希望在您的支持下,我可以自行转换剩余的语句.
提前致谢
迈克尔
您似乎想转换 Lambda 并添加事件处理程序.
来自 C# 的 Lambda
.Where(x => x.Foo = 1).Do(x => x.Bar())
翻译成
.Where(function(x) x.Foo = 1).Do(sub(x) x.Bar())
在 VB.Net 中,您必须考虑 Labda 是实际执行函数还是子函数并相应地对其进行编码.
在 C# 中添加事件
engine.Idling += MyEventHandler
在VB.Net
AddHandler engine.Idling, AddressOf MyEventHandler
VB.Net
让你添加这样的事件.删除事件由关键字 RemoveHandler
While reading the NSubstitute tutorial i convert the samples written in C# to VB.net to understand the functionality, but I need your support for these (unrelated) statements, which I can't convert despite all the care taken:
1.
calculator().Received().Add(1, Arg.Is(Of Integer)(function(x) new[] {-2,-5,-10}.Contains(x)))
2.
Note: foo is a derived object from an interface with a void method called "SayHello"
foo.When(x >= x.SayHello("World")).Do(x => counter++);
3.
calculator().When(x >= x.Add(-2, -2)).Do(x => { throw new Exception(); });
Note: engine is a derived object from this interface:
public interface IEngine {
event EventHandler Idling;
event EventHandler<LowFuelWarningEventArgs> LowFuelWarning;
event Action<int> RevvedAt;
}
4.
engine.Idling += (sender, args) => wasCalled = true;
5.
engine.Idling += Raise.EventWith(new object(), new EventArgs());
6.
engine.RevvedAt += rpm => revvedAt = rpm;
With your support I hope, I'm able to convert the remaining statements on my own.
Thank you in advance
Michael
It seems you want to convert Lambda's and adding event handlers.
Lambda from c#
.Where(x => x.Foo = 1)
.Do(x => x.Bar())
translates into
.Where(function(x) x.Foo = 1)
.Do(sub(x) x.Bar())
In VB.Net you have to take into account if the Labda is actually performing a function or a sub and code it accordingly.
Adding events in c#
engine.Idling += MyEventHandler
in VB.Net
AddHandler engine.Idling, AddressOf MyEventHandler
VB.Net
lets u add the event like this. Removing an event is done by the keyword RemoveHandler
这篇关于将包含 NSubstitute 代码的 C# 语句转换为 VB.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!