Beispiel #1
0
        public ComEventsMethod AddMethod(int dispid)
        {
            ComEventsMethod method = new ComEventsMethod(dispid);

            _methods = ComEventsMethod.Add(_methods, method);
            return(method);
        }
Beispiel #2
0
        public static ComEventsMethod?Remove(ComEventsMethod methods, ComEventsMethod method)
        {
            Debug.Assert(methods != null, "removing method from empty methods collection");
            Debug.Assert(method != null, "specify method is null");

            if (methods == method)
            {
                return(methods._next);
            }
            else
            {
                ComEventsMethod?current = methods;

                while (current != null && current._next != method)
                {
                    current = current._next;
                }

                if (current != null)
                {
                    current._next = method._next;
                }

                return(methods);
            }
        }
Beispiel #3
0
        public void AddHandler(int dispid, object func)
        {
            ComEventsMethod method = FindMethod(dispid);

            if (method == null)
            {
                method = AddMethod(dispid);
            }

            if (func is Delegate d)
            {
                method.AddDelegate(d);
            }
            else
            {
                method.AddDelegate(new SplatCallSite.InvokeDelegate(new SplatCallSite(func).Invoke), wrapArgs: true);
            }
        }
Beispiel #4
0
        public void RemoveHandler(int dispid, object func)
        {
            ComEventsMethod sinkEntry = FindMethod(dispid);

            if (sinkEntry == null)
            {
                return;
            }

            if (func is Delegate d)
            {
                sinkEntry.RemoveDelegate(d);
            }
            else
            {
                // Remove the delegate from multicast delegate chain.
                // We will need to find the delegate that corresponds
                // to the func handler we want to remove. This will be
                // easy since we Target property of the delegate object
                // is a ComEventCallContext object.
                sinkEntry.RemoveDelegates(d => d.Target is SplatCallSite callContext && callContext._callable.Equals(func));
            }

            // If the delegates chain is empty - we can remove
            // corresponding ComEvenSinkEntry
            if (sinkEntry.Empty)
            {
                RemoveMethod(sinkEntry);
            }

            if (_methods == null || _methods.Empty)
            {
                Unadvise();
                _iidSourceItf = Guid.Empty;
            }
        }
Beispiel #5
0
 public static ComEventsMethod Add(ComEventsMethod?methods, ComEventsMethod method)
 {
     method._next = methods;
     return(method);
 }
Beispiel #6
0
 public ComEventsMethod?FindMethod(int dispid)
 {
     return(ComEventsMethod.Find(_methods, dispid));
 }
Beispiel #7
0
 public ComEventsMethod?RemoveMethod(ComEventsMethod method)
 {
     _methods = ComEventsMethod.Remove(_methods !, method);
     return(_methods);
 }