开发者

IMessenger.Send Missing Overload That Accepts a Token

开发者 https://www.devze.com 2023-01-04 17:17 出处:网络
Not sure if this was a design decision but IMessenger.Send seems to be missing overload that ac开发者_运维知识库cepts a tokenAssuming that by \"token\" you mean a string that identifies something abou

Not sure if this was a design decision but IMessenger.Send seems to be missing overload that ac开发者_运维知识库cepts a token


Assuming that by "token" you mean a string that identifies something about the message, there are several things you can do.

  1. You can use the NotificationMessage class as the message you're sending.

    Messenger.Default.Send(new NotificationMessage("Token"));
    
  2. If you want to use something other than a string as a token, you can use NotificationMessage.

    Messenger.Default.Send(new NotificationMessage<IToken>(new Token()));
    
  3. You can create your own message class and use it. This lets you register for only messages of your custom type. This is what I recommend.

    public class ErrorMessage : GenericMessage<Exception>
    {
        public ErrorMessage(Exception content) : base(content)
        {
        }
        public ErrorMessage(object sender, Exception content) : base(sender, content)
        {
        }
        public ErrorMessage(object sender, object target, Exception content) : base(sender, target, content)
        {
        }
    }
    
0

精彩评论

暂无评论...
验证码 换一张
取 消