本文整理汇总了C#中Closure.Invoke方法的典型用法代码示例。如果您正苦于以下问题:C# Closure.Invoke方法的具体用法?C# Closure.Invoke怎么用?C# Closure.Invoke使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Closure
的用法示例。
在下文中一共展示了Closure.Invoke方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ShouldBeAbleToNestClosures
public void ShouldBeAbleToNestClosures()
{
MathOperation add = delegate(int a, int b) { return a + b; };
Closure doMath = new Closure(add, new Closure(add, new Closure(add, 1, 1), 1), 1);
int result = (int) doMath.Invoke();
Assert.IsTrue(result == 4);
}
示例2: ShouldBeAbleToCurryArguments
public void ShouldBeAbleToCurryArguments()
{
object source = new object();
EventArgs args = new EventArgs();
ITestCounter counter = mock.NewMock<ITestCounter>();
Expect.Once.On(counter).Method("Increment").WithAnyArguments();
EventHandler dummyHandler = delegate(object eventSource, EventArgs e)
{
// The arguments passed to the
// delegate should match the ones
// given
Assert.AreSame(eventSource, source);
Assert.AreSame(e, args);
counter.Increment();
};
Closure closure = new Closure(dummyHandler, source);
Assert.IsTrue(closure.Arguments.Contains(source));
closure.Invoke(args);
}