Ejemplo n.º 1
0
        /// <summary>
        /// Used to send a message to Components.
        /// </summary>
        /// <param name="message">The message to be sent.</param>
        /// <param name="target">The target Component for the message (if any).</param>
        public object SendMessage(string message, string target, params object[] parameters)
        {
            MethodInfo info = GetType().GetMethod(message);

            if (info != null)
            {
                info.Invoke(this, parameters);
            }
            else
            {
                if (target == null)
                {
                    var cs = (from c in comps
                              where c.GetType().GetMethod(message) != null
                              select c).ToList();

                    object obj = null;

                    foreach (var comp in cs)
                    {
                        obj = comp.GetType().GetMethod(message).Invoke(comp, parameters);
                    }

                    return(obj);
                }
                else
                {
                    ObjectComponent comp = FindComponent(target);

                    if (comp == null)
                    {
                        comp = FindComponent(AssemblyManager.GetType(target));
                    }

                    object obj = null;

                    if (comp != null)
                    {
                        if (comp.GetType().GetMethod(message) != null)
                        {
                            obj = comp.GetType().GetMethod(message).Invoke(comp, parameters);
                        }
                    }

                    return(obj);
                }
            }

            return(null);
        }