コード例 #1
0
        /// <summary>
        /// Sends messenger event named <paramref name="eventMethodName"/> to receiver.
        /// </summary>
        /// <param name="receiver">Receiver of messenger</param>
        /// <param name="eventMethodName">Event message receiving method</param>
        /// <param name="sender">The sender argument of event method.</param>
        /// <param name="eventArgs">The e argument of event method.</param>
        public static void SendMessenger(this object receiver, string eventMethodName, object sender, EventArgs eventArgs)
        {
            if (receiver is null)
            {
                throw new ArgumentNullException(nameof(receiver));
            }

            DynamicMessengerRecipient recipient = receiver.GetRecipient();

            recipient.SendMessenger(receiver, eventMethodName, sender, eventArgs);
        }
コード例 #2
0
 /// <summary>
 /// Gets a <see cref="DynamicMessengerRecipient"/> associated with a specified type.
 /// </summary>
 /// <param name="receiverType">The type to locate.</param>
 /// <returns>A <see cref="DynamicMessengerRecipient"/> that is associated with the <paramref name="receiverType"/> type.</returns>
 public static DynamicMessengerRecipient GetRecipient(this Type receiverType)
 {
     if (recipients.ContainsKey(receiverType))
     {
         return(recipients[receiverType]);
     }
     else
     {
         DynamicMessengerRecipient output = new DynamicMessengerRecipient(receiverType);
         recipients.Add(receiverType, output);
         return(output);
     }
 }
コード例 #3
0
        /// <summary>
        /// Get delegate of event method
        /// </summary>
        /// <param name="target">Target of delegate</param>
        /// <param name="methodName">Method name</param>
        /// <returns>Delegate of method in target</returns>
        public static Delegate GetDelegate(object target, string methodName)
        {
            if (target is null)
            {
                throw new ArgumentNullException(nameof(target));
            }

            if (string.IsNullOrWhiteSpace(methodName) || methodName.Contains(" "))
            {
                throw new ArgumentException("Argument cannot be null, empty, or whitespace, nor can it contain whitespace.", nameof(methodName));
            }

            DynamicMessengerRecipient recipient = target.GetRecipient();

            return(recipient.GetDelegateEvent(target, methodName));
        }