当前位置: 首页>>代码示例>>C#>>正文


C# EventAggregator.Trigger方法代码示例

本文整理汇总了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");
        }
开发者ID:puppt,项目名称:GW2Emu,代码行数:55,代码来源:EventAggregatorTest.cs

示例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.");
        }
开发者ID:ephe-meral,项目名称:EventAggregator-CSharp,代码行数:36,代码来源:Program.cs


注:本文中的EventAggregator.Trigger方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。