Esempio n. 1
0
        public static ComEventSink FromRuntimeCallableWrapper(object rcw, Guid sourceIid, bool createIfNotFound)
        {
            List <ComEventSink> comEventSinks = ComEventSinksContainer.FromRuntimeCallableWrapper(rcw, createIfNotFound);

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

            ComEventSink comEventSink = null;

            lock (comEventSinks)
            {
                foreach (ComEventSink sink in comEventSinks)
                {
                    if (sink._sourceIid == sourceIid)
                    {
                        comEventSink = sink;
                        break;
                    }
                    else if (sink._sourceIid == 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 == true)
                {
                    comEventSink = new ComEventSink(rcw, sourceIid);
                    comEventSinks.Add(comEventSink);
                }
            }

            return(comEventSink);
        }