Пример #1
0
        public static ComEventsSink?Remove(ComEventsSink sinks, ComEventsSink sink)
        {
            Debug.Assert(sinks != null, "removing event sink from empty sinks collection");
            Debug.Assert(sink != null, "specify event sink is null");

            ComEventsSink?toReturn = sinks;

            if (sink == sinks)
            {
                toReturn = sinks._next;
            }
            else
            {
                ComEventsSink?current = sinks;
                while (current != null && current._next != sink)
                {
                    current = current._next;
                }

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

            sink.Unadvise();

            return(toReturn);
        }
Пример #2
0
        public static ComEventsSink FromRuntimeCallableWrapper(object rcw, Guid sourceIid, bool createIfNotFound)
        {
            List <ComEventsSink> comEventSinks = ComEventSinksContainer.FromRuntimeCallableWrapper(rcw, createIfNotFound);

            if (comEventSinks == null)
            {
                return(null);
            }

            ComEventsSink comEventSink = null;

            lock (comEventSinks)
            {
                foreach (ComEventsSink sink in comEventSinks)
                {
                    if (sink._iidSourceItf == sourceIid)
                    {
                        comEventSink = sink;
                        break;
                    }

                    if (sink._iidSourceItf == Guid.Empty)
                    {
                        // we found a ComEventSink object that
                        // was previously disposed. Now we will reuse it.
                        sink.Initialize(rcw, sourceIid);
                        comEventSink = sink;
                    }
                }

                if (comEventSink == null && createIfNotFound)
                {
                    comEventSink = new ComEventsSink(rcw, sourceIid);
                    comEventSinks.Add(comEventSink);
                }
            }

            return(comEventSink);
        }
Пример #3
0
 public static ComEventsSink Add(ComEventsSink?sinks, ComEventsSink sink)
 {
     sink._next = sinks;
     return(sink);
 }