本文整理汇总了C#中EventAggregator.Trigger方法的典型用法代码示例。如果您正苦于以下问题:C# EventAggregator.Trigger方法的具体用法?C# EventAggregator.Trigger怎么用?C# EventAggregator.Trigger使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EventAggregator
的用法示例。
在下文中一共展示了EventAggregator.Trigger方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestCase
public void TestCase()
{
// create the event aggregator and the objects
// that contains the handler methods
var aggr = new EventAggregator();
var handlerObj1 = new TestHandlers();
var handlerObj2 = new TestHandlers();
aggr.Register(handlerObj1);
aggr.Register(handlerObj2);
// create some mock events and set their sample values
var evt1 = new Event1(); evt1.Foo = 1337;
var evt2 = new Event2(); evt2.Bar = "Hello";
// trigger the events: 1st time
aggr.Trigger(evt1);
aggr.Trigger(evt2);
Assert.IsTrue(handlerObj1.GotEvt1);
Assert.AreEqual(handlerObj1.Evt1Data, 1337);
Assert.IsTrue(handlerObj2.GotEvt1);
Assert.AreEqual(handlerObj2.Evt1Data, 1337);
Assert.IsTrue(handlerObj1.GotEvt2);
Assert.AreEqual(handlerObj1.Evt2Data, "Hello");
Assert.IsTrue(handlerObj2.GotEvt2);
Assert.AreEqual(handlerObj2.Evt2Data, "Hello");
// prepare the handlers for the next test
handlerObj1.Reset();
handlerObj2.Reset();
evt1.Foo = 42;
evt2.Bar = "Blubb";
// trigger the events: 2st time
aggr.Trigger(evt2);
aggr.Trigger(evt1);
Assert.IsTrue(handlerObj1.GotEvt1);
Assert.AreEqual(handlerObj1.Evt1Data, 42);
Assert.IsTrue(handlerObj2.GotEvt1);
Assert.AreEqual(handlerObj2.Evt1Data, 42);
Assert.IsTrue(handlerObj1.GotEvt2);
Assert.AreEqual(handlerObj1.Evt2Data, "Blubb");
Assert.IsTrue(handlerObj2.GotEvt2);
Assert.AreEqual(handlerObj2.Evt2Data, "Blubb");
}
示例2: Main
public static void Main(string[] args)
{
Console.WriteLine("Starting the tests...");
// create the event aggregator and the object
// that contains the handler methods
var aggr = new EventAggregator();
//var aggr = new EventAggregator.ConcurrentEventAggregator();
var handlerObj1 = new TestHandlers("1st handlers");
var handlerObj2 = new TestHandlers("2nd handlers");
// call the convenience method to register the handlers
// with the aggregator
aggr.Register(handlerObj1);
aggr.Register(handlerObj2);
// create some mock events and set their sample values
var fooEvt = new SomeEvent();
var barEvt = new SomeOtherEvent();
fooEvt.Foo = 1337;
barEvt.Bar = "Hello";
// trigger the events: 1st time
aggr.Trigger(fooEvt);
aggr.Trigger(barEvt);
fooEvt.Foo = 42;
barEvt.Bar = "Blubb";
// trigger the events: 2st time
aggr.Trigger(barEvt);
aggr.Trigger(fooEvt);
Console.WriteLine("Finished running the tests.");
}