本文整理汇总了C#中Messenger.Broadcast方法的典型用法代码示例。如果您正苦于以下问题:C# Messenger.Broadcast方法的具体用法?C# Messenger.Broadcast怎么用?C# Messenger.Broadcast使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Messenger
的用法示例。
在下文中一共展示了Messenger.Broadcast方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestMultipleMessageTypes
public void TestMultipleMessageTypes()
{
var messenger = new Messenger();
var recipient = new OldTestRecipient();
messenger.Register(recipient, typeof(OldTestMessage));
messenger.Register(recipient, typeof(GenericMessage<InvalidOperationException>));
messenger.Register(recipient, typeof(GenericMessage<MissingMethodException>));
Assert.IsNull(recipient.Content);
Assert.IsNull(recipient.ObjectContent1);
Assert.IsNull(recipient.ObjectContent2);
var testObject1 = new InvalidOperationException();
var genericMessage = new GenericMessage<InvalidOperationException>(this, testObject1);
messenger.Broadcast(genericMessage);
Assert.AreEqual(this, recipient.Sender);
Assert.IsNull(recipient.Content);
Assert.AreEqual(testObject1, recipient.ObjectContent1);
Assert.IsNull(recipient.ObjectContent2);
var testObject2 = new MissingMethodException();
var genericMessage2 = new GenericMessage<MissingMethodException>(this, testObject2);
messenger.Broadcast(genericMessage2);
Assert.AreEqual(this, recipient.Sender);
Assert.IsNull(recipient.Content);
Assert.AreEqual(testObject1, recipient.ObjectContent1);
Assert.AreEqual(testObject2, recipient.ObjectContent2);
const string TestString = "Hello world";
var message = new OldTestMessage(this, TestString);
messenger.Broadcast(message);
Assert.AreEqual(this, recipient.Sender);
Assert.AreEqual(TestString, recipient.Content);
Assert.AreEqual(testObject1, recipient.ObjectContent1);
Assert.AreEqual(testObject2, recipient.ObjectContent2);
}
示例2: TestMultipleRecipients
public void TestMultipleRecipients()
{
var messenger = new Messenger();
var recipient1 = new OldTestRecipient();
var recipient2 = new OldTestRecipient();
var recipient3 = new OldTestRecipient();
messenger.Register(recipient1, typeof(OldTestMessage));
messenger.Register(recipient2, typeof(OldTestMessage));
messenger.Register(recipient3, typeof(OldTestMessage));
Assert.IsNull(recipient1.Sender);
Assert.IsNull(recipient1.Content);
Assert.IsNull(recipient2.Content);
Assert.IsNull(recipient2.Sender);
Assert.IsNull(recipient3.Content);
Assert.IsNull(recipient3.Sender);
const string TestString = "Hello world";
var message = new OldTestMessage(this, TestString);
messenger.Broadcast(message);
Assert.AreEqual(TestString, recipient1.Content);
Assert.AreEqual(this, recipient1.Sender);
Assert.AreEqual(TestString, recipient2.Content);
Assert.AreEqual(this, recipient2.Sender);
Assert.AreEqual(TestString, recipient3.Content);
Assert.AreEqual(this, recipient3.Sender);
}
示例3: TestMultipleRecipientsWithObjects
public void TestMultipleRecipientsWithObjects()
{
var messenger = new Messenger();
var recipient1 = new OldTestRecipient();
var recipient2 = new OldTestRecipient();
var recipient3 = new OldTestRecipient();
messenger.Register(recipient1, typeof(GenericMessage<InvalidOperationException>));
messenger.Register(recipient2, typeof(GenericMessage<InvalidOperationException>));
messenger.Register(recipient3, typeof(GenericMessage<InvalidOperationException>));
Assert.IsNull(recipient1.Sender);
Assert.IsNull(recipient1.Content);
Assert.IsNull(recipient2.Content);
Assert.IsNull(recipient2.Sender);
Assert.IsNull(recipient3.Content);
Assert.IsNull(recipient3.Sender);
var testContent = new InvalidOperationException();
var message = new GenericMessage<InvalidOperationException>(this, testContent);
messenger.Broadcast(message);
Assert.AreEqual(this, recipient1.Sender);
Assert.AreEqual(testContent, recipient1.ObjectContent1);
Assert.AreEqual(this, recipient2.Sender);
Assert.AreEqual(testContent, recipient2.ObjectContent1);
Assert.AreEqual(this, recipient3.Sender);
Assert.AreEqual(testContent, recipient3.ObjectContent1);
}