本文介绍了MvvmLight打印消息进行调试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种简单的方法可以打印所有Messenger.Default.Send()进行调试?不想覆盖它们.

Is there a simple way to print all Messenger.Default.Send() to debug? Don't want to override them.

推荐答案

是的,所以我最后用Messenger自己的包装器结束了.没有明智的解决方案,只有简单的包装即可.万一其他人会需要它:

Yep, so i ended up with own wrapper around Messenger. No smart solutions, just straightforward wrapping. In case, anybody else would need it:

public static class MvvmLightMessenger
{
    public static void Register<TMessage>(object recipient, Action<TMessage> action)
    {
        Messenger.Default.Register(recipient,action);
    }

    public static void Register<TMessage>(object recipient, bool receiveDerivedMessagesToo, Action<TMessage> action)
    {
        Messenger.Default.Register(recipient, receiveDerivedMessagesToo, action);
    }

    public static void Register<TMessage>(object recipient, object token, Action<TMessage> action)
    {
        Messenger.Default.Register(recipient, token, action);
    }

    public static void Register<TMessage>(object recipient, object token, bool receiveDerivedMessagesToo, Action<TMessage> action)
    {
        Messenger.Default.Register(recipient, token, receiveDerivedMessagesToo, action);
    }





    public static void Send<TMessage>(TMessage message)
    {
        Debug.WriteLine("{!} Message: " + message);
        Messenger.Default.Send<TMessage>(message);
    }

    public static void Send<TMessage, TTarget>(TMessage message)
    {
        Debug.WriteLine("{!} Message: " + message + " to target: " + typeof(TTarget));
        Messenger.Default.Send<TMessage, TTarget>(message);
    }

    public static void Send<TMessage>(TMessage message, object token)
    {
        Debug.WriteLine("{!} Message: " + message + " token: " + token);
        Messenger.Default.Send<TMessage>(message, token);
    }







    public static void Unregister<TMessage>(object recipient)
    {
        Messenger.Default.Unregister<TMessage>(recipient);
    }

    public static void Unregister<TMessage>(object recipient, Action<TMessage> action)
    {
        Messenger.Default.Unregister<TMessage>(recipient, action);
    }

    public static void Unregister<TMessage>(object recipient, object token)
    {
        Messenger.Default.Unregister<TMessage>(recipient, token);
    }

    public static void Unregister<TMessage>(object recipient, object token, Action<TMessage> action)
    {
        Messenger.Default.Unregister<TMessage>(recipient, token, action);
    }
}

这篇关于MvvmLight打印消息进行调试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-25 20:17