From 147d6faef481df8027eb731114efd38f299bd454 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 16 May 2020 23:15:38 +0200 Subject: [PATCH] Added default implementations to IMessenger --- .../Messaging/IMessenger.cs | 54 ++++++++++++++++--- 1 file changed, 48 insertions(+), 6 deletions(-) diff --git a/Microsoft.Toolkit.Mvvm/Messaging/IMessenger.cs b/Microsoft.Toolkit.Mvvm/Messaging/IMessenger.cs index 6950ad8e..ebcef3e0 100644 --- a/Microsoft.Toolkit.Mvvm/Messaging/IMessenger.cs +++ b/Microsoft.Toolkit.Mvvm/Messaging/IMessenger.cs @@ -21,7 +21,14 @@ namespace Microsoft.Toolkit.Mvvm.Messaging /// This method will use the default channel to check for the requested registration. [Pure] bool IsRegistered(object recipient) - where TMessage : class; + where TMessage : class +#if NETSTANDARD2_1 + { + return IsRegistered(recipient, default); + } +#else + ; +#endif /// /// Checks whether or not a given recipient has already been registered for a message. @@ -45,7 +52,14 @@ namespace Microsoft.Toolkit.Mvvm.Messaging /// Thrown when trying to register the same message twice. /// This method will use the default channel to perform the requested registration. void Register(object recipient, Action action) - where TMessage : class; + where TMessage : class +#if NETSTANDARD2_1 + { + Register(recipient, default(Messenger.Unit), action); + } +#else + ; +#endif /// /// Registers a recipient for a given type of message. @@ -81,7 +95,14 @@ namespace Microsoft.Toolkit.Mvvm.Messaging /// If the recipient has no registered handler, this method does nothing. /// void Unregister(object recipient) - where TMessage : class; + where TMessage : class +#if NETSTANDARD2_1 + { + Unregister(recipient, default); + } +#else + ; +#endif /// /// Unregisters a recipient from all messages on a specific channel. @@ -115,7 +136,14 @@ namespace Microsoft.Toolkit.Mvvm.Messaging /// a new instance and send that to its recipients. /// void Send() - where TMessage : class, new(); + where TMessage : class, new() +#if NETSTANDARD2_1 + { + Send(new TMessage(), default(Messenger.Unit)); + } +#else + ; +#endif /// /// Sends a message of the specified type to all registered recipients. @@ -123,7 +151,14 @@ namespace Microsoft.Toolkit.Mvvm.Messaging /// The type of message to send. /// The message to send. void Send(TMessage message) - where TMessage : class; + where TMessage : class +#if NETSTANDARD2_1 + { + Send(message, default(Messenger.Unit)); + } +#else + ; +#endif /// /// Sends a message of the specified type to all registered recipients. @@ -137,7 +172,14 @@ namespace Microsoft.Toolkit.Mvvm.Messaging /// void Send(TToken token) where TMessage : class, new() - where TToken : IEquatable; + where TToken : IEquatable +#if NETSTANDARD2_1 + { + Send(new TMessage(), token); + } +#else + ; +#endif /// /// Sends a message of the specified type to all registered recipients.