public static string GetEffectiveDelegateType(this EventResponseSave ers, IElement containingElement)
        {
            if (ers.GetIsTunneling())
            {
                IElement          tunneledElement;
                EventResponseSave tunneledTo = ers.GetEventThisTunnelsTo(containingElement, out tunneledElement);

                if (tunneledTo != null)
                {
                    return(tunneledTo.GetEffectiveDelegateType(tunneledElement));
                }
            }

            EventSave eventSave = ers.GetEventSave();

            string delegateType;

            if (eventSave != null && !string.IsNullOrEmpty(eventSave.DelegateType))
            {
                delegateType = eventSave.DelegateType;
            }
            else if (!string.IsNullOrEmpty(ers.DelegateType))
            {
                delegateType = ers.DelegateType;
            }
            else
            {
                delegateType = "EventHandler";
            }

            if (delegateType == "Action")
            {
                delegateType = "System.Action";
            }

            return(delegateType);
        }
        public static EventResponseSave GetEventThisTunnelsTo(this EventResponseSave instance, IElement element, out IElement containingElement)
        {
            if (instance.GetIsTunneling() == false)
            {
                containingElement = null;
                return(null);
            }
            else
            {
                NamedObjectSave nos = element.GetNamedObject(instance.SourceObject);

                if (nos != null && nos.SourceType == SourceType.Entity)
                {
                    containingElement = ObjectFinder.Self.GetIElement(nos.SourceClassType);

                    if (containingElement != null)
                    {
                        return(containingElement.GetEvent(instance.SourceObjectEvent));
                    }
                }
            }
            containingElement = null;
            return(null);
        }
        public static string GetArgsForMethod(this EventResponseSave ers, IElement containingElement)
        {
            EventSave eventSave = ers.GetEventSave();


            string args      = null;
            bool   foundArgs = false;

            if (eventSave != null)
            {
                args      = eventSave.Arguments;
                foundArgs = true;
            }
            else if (ers.GetIsTunneling())
            {
                IElement          tunneledContainingElement;
                EventResponseSave tunneled = ers.GetEventThisTunnelsTo(containingElement, out tunneledContainingElement);

                if (tunneled != null)
                {
                    return(tunneled.GetArgsForMethod(tunneledContainingElement));
                }
            }
            else if (!string.IsNullOrEmpty(ers.DelegateType))
            {
                if (ers.DelegateType.StartsWith("System.Action<"))
                {
                    string delegateType = ers.DelegateType;

                    int startOfGeneric  = delegateType.IndexOf("<") + 1;
                    int endofGeneric    = delegateType.LastIndexOf(">");
                    int lengthOfGeneric = endofGeneric - startOfGeneric;

                    string genericType = delegateType.Substring(startOfGeneric, lengthOfGeneric);

                    args      = genericType + " value";
                    foundArgs = true;
                }
                else
                {
                    Type type = TypeManager.GetTypeFromString(ers.DelegateType);

                    if (type != null)
                    {
                        MethodInfo      methodInfo = type.GetMethod("Invoke");
                        ParameterInfo[] parameters = methodInfo.GetParameters();
                        for (int i = 0; i < parameters.Length; i++)
                        {
                            if (i != 0)
                            {
                                args += ", ";
                            }

                            ParameterInfo param = parameters[i];

                            args += param.ParameterType.FullName + " " + param.Name;
                            Console.WriteLine("{0} {1}", param.ParameterType.Name, param.Name);
                        }

                        foundArgs = true;
                    }
                }
            }

            if (!foundArgs)
            {
                args = "object sender, EventArgs e";
            }

            return(args);
        }
 public static bool GetIsNewEvent(this EventResponseSave eventResponseSave)
 {
     return(!eventResponseSave.GetIsExposing() && !eventResponseSave.GetIsTunneling() &&
            !string.IsNullOrEmpty(eventResponseSave.DelegateType));
 }