コード例 #1
0
 public static void Combine(object rcw, Guid iid, int dispid, Delegate d)
 {
     rcw = ComEventsHelper.UnwrapIfTransparentProxy(rcw);
     lock (rcw)
     {
         ComEventsInfo local_2 = ComEventsInfo.FromObject(rcw);
         ComEventsSink local_3 = local_2.FindSink(ref iid) ?? local_2.AddSink(ref iid);
         (local_3.FindMethod(dispid) ?? local_3.AddMethod(dispid)).AddDelegate(d);
     }
 }
コード例 #2
0
 public override void AddEventHandler(object target, Delegate handler)
 {
     if (Marshal.IsComObject(target))
     {
         // retrieve sourceIid and dispid
         GetDataForComInvocation(_innerEventInfo, out Guid sourceIid, out int dispid);
         ComEventsHelper.Combine(target, sourceIid, dispid, handler);
     }
     else
     {
         // we are dealing with a managed object - just add the delegate through reflection
         _innerEventInfo.AddEventHandler(target, handler);
     }
 }
コード例 #3
0
        public static Delegate Remove(object rcw, Guid iid, int dispid, Delegate d)
        {
            rcw = ComEventsHelper.UnwrapIfTransparentProxy(rcw);
            object   obj = rcw;
            Delegate result;

            lock (obj)
            {
                ComEventsInfo comEventsInfo = ComEventsInfo.Find(rcw);
                if (comEventsInfo == null)
                {
                    result = null;
                }
                else
                {
                    ComEventsSink comEventsSink = comEventsInfo.FindSink(ref iid);
                    if (comEventsSink == null)
                    {
                        result = null;
                    }
                    else
                    {
                        ComEventsMethod comEventsMethod = comEventsSink.FindMethod(dispid);
                        if (comEventsMethod == null)
                        {
                            result = null;
                        }
                        else
                        {
                            comEventsMethod.RemoveDelegate(d);
                            if (comEventsMethod.Empty)
                            {
                                comEventsMethod = comEventsSink.RemoveMethod(comEventsMethod);
                            }
                            if (comEventsMethod == null)
                            {
                                comEventsSink = comEventsInfo.RemoveSink(comEventsSink);
                            }
                            if (comEventsSink == null)
                            {
                                Marshal.SetComObjectData(rcw, typeof(ComEventsInfo), null);
                                GC.SuppressFinalize(comEventsInfo);
                            }
                            result = d;
                        }
                    }
                }
            }
            return(result);
        }
コード例 #4
0
 public override void RemoveEventHandler(object target, Delegate handler)
 {
     if (Marshal.IsComObject(target))
     {
         Guid guid;
         int  num;
         GetDataForComInvocation(this._innerEventInfo, out guid, out num);
         new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Demand();
         ComEventsHelper.Remove(target, guid, num, handler);
     }
     else
     {
         this._innerEventInfo.RemoveEventHandler(target, handler);
     }
 }
コード例 #5
0
        public static void Combine(object rcw, Guid iid, int dispid, Delegate d)
        {
            rcw = ComEventsHelper.UnwrapIfTransparentProxy(rcw);
            object obj = rcw;

            lock (obj)
            {
                ComEventsInfo comEventsInfo = ComEventsInfo.FromObject(rcw);
                ComEventsSink comEventsSink = comEventsInfo.FindSink(ref iid);
                if (comEventsSink == null)
                {
                    comEventsSink = comEventsInfo.AddSink(ref iid);
                }
                ComEventsMethod comEventsMethod = comEventsSink.FindMethod(dispid);
                if (comEventsMethod == null)
                {
                    comEventsMethod = comEventsSink.AddMethod(dispid);
                }
                comEventsMethod.AddDelegate(d);
            }
        }
コード例 #6
0
 public static Delegate Remove(object rcw, Guid iid, int dispid, Delegate d)
 {
     rcw = ComEventsHelper.UnwrapIfTransparentProxy(rcw);
     lock (rcw)
     {
         ComEventsInfo local_2 = ComEventsInfo.Find(rcw);
         if (local_2 == null)
         {
             return((Delegate)null);
         }
         ComEventsSink local_3 = local_2.FindSink(ref iid);
         if (local_3 == null)
         {
             return((Delegate)null);
         }
         ComEventsMethod local_4 = local_3.FindMethod(dispid);
         if (local_4 == null)
         {
             return((Delegate)null);
         }
         local_4.RemoveDelegate(d);
         if (local_4.Empty)
         {
             local_4 = local_3.RemoveMethod(local_4);
         }
         if (local_4 == null)
         {
             local_3 = local_2.RemoveSink(local_3);
         }
         if (local_3 == null)
         {
             Marshal.SetComObjectData(rcw, (object)typeof(ComEventsInfo), (object)null);
             GC.SuppressFinalize((object)local_2);
         }
         return(d);
     }
 }