Exemplo n.º 1
0
    public void SwapGroupMethod(string groupName, EventMethodInfo method, Reorder direction)
    {
        var group = groups.Find(x => x.GroupName.Equals(groupName));

        if (group == null)
        {
            throw new ArgumentException("group was not found!");
        }

        if (!group.ContainsMethod(method))
        {
            throw new ArgumentException("method was not found in the group!");
        }

        var indexOfMethod = group.IndexOfMethod(x => x.Equals(method));

        var nextIndex = indexOfMethod;

        if (direction == Reorder.MoveUp)
        {
            nextIndex--;
        }
        else if (direction == Reorder.MoveDown)
        {
            nextIndex++;
        }

        if (group.Methods.IndexInRange(nextIndex))
        {
            group.SwapMethods(indexOfMethod, nextIndex);
        }
    }
Exemplo n.º 2
0
    public void ReplaceMethod(EventMethodInfo oldMethod, EventMethodInfo newMethod)
    {
        if (IsReadOnly)
        {
            throw new MemberAccessException("attribute is read-only (non-Modifiable)!");
        }

        if (oldMethod == null || newMethod == null)
        {
            throw new ArgumentException("cannot accept null arguments");
        }


        var index = _methods.FindIndex(oldMethod.Equals);

        if (index == -1)
        {
            throw new ArgumentException("oldMethod was not found");
        }


        if (index != -1)
        {
            _methods[index] = newMethod.Clone() as EventMethodInfo;
        }
    }
Exemplo n.º 3
0
    public void ChangeEventGroup(string groupName, string otherGroupName, EventMethodInfo method)
    {
        if (!ContainsGroup(groupName))
        {
            throw new ArgumentException("group was not found!");
        }

        if (!ContainsGroup(otherGroupName))
        {
            throw new ArgumentException("other group was not found!");
        }

        if (!IsEventMethodExists(groupName, method))
        {
            throw new ArgumentException("method was not found in the group");
        }

        if (IsEventMethodExists(otherGroupName, method))
        {
            throw new ArgumentException("method with the same signature already exists in the other group");
        }

        RemoveEvent(groupName, method);
        AddEvent(otherGroupName, method);

        if (_onModifyListener != null)
        {
            _onModifyListener();
        }
    }
Exemplo n.º 4
0
 public bool IsEventMethodExists(string groupName, EventMethodInfo method)
 {
     if (!ContainsGroup(groupName))
     {
         return(false);
     }
     return(groups.Where(group => group.GroupName.Equals(groupName)).Any(group => group.ContainsMethod(method))); //PluginEvents.UsedEvents.Exists(x=>x.Name== name);
 }
Exemplo n.º 5
0
 internal void HookUpAutomaticHandlers()
 {
     if (this.SupportAutoEvents)
     {
         object      obj2       = _eventListCache[base.GetType()];
         IDictionary dictionary = null;
         if (obj2 == null)
         {
             lock (_lockObject)
             {
                 obj2 = _eventListCache[base.GetType()];
                 if (obj2 == null)
                 {
                     dictionary = new ListDictionary();
                     this.GetDelegateInformation(dictionary);
                     if (dictionary.Count == 0)
                     {
                         obj2 = _emptyEventSingleton;
                     }
                     else
                     {
                         obj2 = dictionary;
                     }
                     _eventListCache[base.GetType()] = obj2;
                 }
             }
         }
         if (obj2 != _emptyEventSingleton)
         {
             dictionary = (IDictionary)obj2;
             foreach (string str in dictionary.Keys)
             {
                 EventMethodInfo info       = (EventMethodInfo)dictionary[str];
                 bool            flag2      = false;
                 MethodInfo      methodInfo = info.MethodInfo;
                 Delegate        delegate2  = base.Events[_eventObjects[str]];
                 if (delegate2 != null)
                 {
                     foreach (Delegate delegate3 in delegate2.GetInvocationList())
                     {
                         if (delegate3.Method.Equals(methodInfo))
                         {
                             flag2 = true;
                             break;
                         }
                     }
                 }
                 if (!flag2)
                 {
                     IntPtr       functionPointer = methodInfo.MethodHandle.GetFunctionPointer();
                     EventHandler handler         = new CalliEventHandlerDelegateProxy(this, functionPointer, info.IsArgless).Handler;
                     base.Events.AddHandler(_eventObjects[str], handler);
                 }
             }
         }
     }
 }
Exemplo n.º 6
0
    public bool RemoveMethod(EventMethodInfo eventMethod)
    {
        if (IsReadOnly)
        {
            throw new MemberAccessException("attribute is read-only (non-Modifiable)!");
        }

        return(_methods.Remove(eventMethod));
    }
Exemplo n.º 7
0
        public virtual void FireEvent02(EventData eventData)
        {
            Debug.Assert(eventData != null && !string.IsNullOrWhiteSpace(eventData.EventName));

            EventMethodName = string.Format("{0}{1}", eventData.EventName, !eventData.EventName.EndsWith("Event") ? "Event" : "");

            EventMethodInfo = GetType().GetMethod(EventMethodName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);

            if (EventMethodInfo != null)
            {
                EventMethodInfo.Invoke(this, new object[] { eventData.EventParam });
            }
        }
Exemplo n.º 8
0
    void DrawBottomButtons()
    {
        GUILayout.BeginHorizontal();


        if (GUILayout.Button(IsInEditMode ? "Edit" : "Create"))
        {
            try
            {
                if (IsInEditMode)
                {
                    var methodToAdd = new EventMethodInfo(eventName, args);
                    if (EventsManager.Instance.GroupsContainer[GroupNames[selectedgroupNamePopupValue]].ContainsMethod(methodToAdd))
                    {
                        throw new ArgumentException("another event method with the same signature already exists.");
                    }
                    EventsManager.Instance.GroupsContainer.RemoveEvent(ContainingGroup, eventmethod);
                    EventsManager.Instance.GroupsContainer.AddEvent(GroupNames[selectedgroupNamePopupValue], methodToAdd);
                }
                else
                {
                    EventsManager.Instance.GroupsContainer.AddEvent(ContainingGroup, new EventMethodInfo(eventName, args));
                }

                Close();
            }
            catch (Exception e)
            {
                errorString = e.Message;
            }
        }


        if (GUILayout.Button("Close"))
        {
            Close();
        }

        GUILayout.EndHorizontal();

        if (!string.IsNullOrEmpty(errorString))
        {
            GUILayout.BeginHorizontal();
            var tempColor = GUI.color;
            GUI.color = Color.red;
            GUILayout.Label(errorString);
            GUI.color = tempColor;
            GUILayout.EndHorizontal();
        }
    }
    public EventMethodModifier(EventMethodsGroup containingGroup, EventMethodInfo method)
    {
        if (containingGroup == null || method == null)
        {
            throw new ArgumentException("arguments cannot be null!");
        }

        if (!containingGroup.ContainsMethod(method))
        {
            throw new ArgumentException("the method must be contained in the group in order!");
        }

        _containingGroup = containingGroup;
        _method          = method;
    }
Exemplo n.º 10
0
    //------------------------------------
    public void AddEvent(string groupName, EventMethodInfo method)
    {
        var temp = groups.Find(x => x.GroupName.Equals(groupName));

        if (temp == null)
        {
            throw new ArgumentException("group was not found!");
        }

        temp.AddMethod(method);


        if (_onModifyListener != null)
        {
            _onModifyListener();
        }
    }
Exemplo n.º 11
0
        private bool GetDelegateInformationFromMethod(string methodName, IDictionary dictionary)
        {
            EventHandler handler = (EventHandler)Delegate.CreateDelegate(typeof(EventHandler), this, methodName, true, false);

            if (handler != null)
            {
                dictionary[methodName] = new EventMethodInfo(handler.Method, false);
                return(true);
            }
            VoidMethod method = (VoidMethod)Delegate.CreateDelegate(typeof(VoidMethod), this, methodName, true, false);

            if (method != null)
            {
                dictionary[methodName] = new EventMethodInfo(method.Method, true);
                return(true);
            }
            return(false);
        }
Exemplo n.º 12
0
    //methods---------------------------------------------------------------------------
    public void AddMethod(EventMethodInfo eventMethod)
    {
        if (IsReadOnly)
        {
            throw new MemberAccessException("attribute is read-only (non-Modifiable)!");
        }

        if (eventMethod == null)
        {
            throw new ArgumentException("cannot add a null method");
        }

        if (_methods.Contains(eventMethod))
        {
            throw new ArgumentException("method with the same signature already exits");
        }


        _methods.Add(eventMethod.Clone() as EventMethodInfo);
    }
Exemplo n.º 13
0
    //----------------------------------------------
    public void Initialize(string containingGroupName, EventMethodInfo eventMethod)
    {
        if (EventsManager.Instance.GroupsContainer.ContainsGroup(containingGroupName))
        {
            ContainingGroup             = containingGroupName;
            selectedgroupNamePopupValue = GroupNames.ToList().IndexOf(containingGroupName);


            if (EventsManager.Instance.GroupsContainer[containingGroupName].ContainsMethod(eventMethod))
            {
                this.eventmethod = eventMethod;
                eventName        = eventMethod.Name;
                Args             = eventMethod.Args.ToList();
            }
        }
        else
        {
            Close();
        }
    }
 private bool GetDelegateInformationFromMethod(string methodName, IDictionary dictionary)
 {
     EventHandler handler = (EventHandler) Delegate.CreateDelegate(typeof(EventHandler), this, methodName, true, false);
     if (handler != null)
     {
         dictionary[methodName] = new EventMethodInfo(handler.Method, false);
         return true;
     }
     VoidMethod method = (VoidMethod) Delegate.CreateDelegate(typeof(VoidMethod), this, methodName, true, false);
     if (method != null)
     {
         dictionary[methodName] = new EventMethodInfo(method.Method, true);
         return true;
     }
     return false;
 }
Exemplo n.º 15
0
 public ReadOnlyEventMethodInfo(EventMethodInfo other) : base(other)
 {
 }
Exemplo n.º 16
0
 public bool ContainsMethod(EventMethodInfo other)
 {
     return(_methods.Exists(x => x.Equals(other)));
 }