示例#1
0
 /// <summary>
 /// 判断控件是否已经绑定事件
 /// </summary>
 /// <param name="control"></param>
 /// <param name="EventName"></param>
 /// <returns></returns>
 public static bool IsBindEvent(object control, string EventName)
 {
     try
     {
         BindingFlags     bindingAttr      = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy;
         Type             typeFromHandle   = typeof(Control);
         FieldInfo        field            = typeFromHandle.GetField("Event" + EventName, bindingAttr);
         PropertyInfo     property         = control.GetType().GetProperty("Events", bindingAttr);
         EventHandlerList eventHandlerList = property.GetValue(control, null) as EventHandlerList;
         if (eventHandlerList != null)
         {
             object   obj       = RuntimeHelpers.GetObjectValue(field.GetValue(control));
             Delegate @delegate = eventHandlerList[obj];
             if (@delegate != null && @delegate.GetInvocationList().Count <Delegate>() > 0)
             {
                 return(true);
             }
         }
         return(false);
     }
     catch (Exception ex)
     {
         if (ex.InnerException != null)
         {
             throw ex.InnerException;
         }
         throw ex;
     }
 }
 internal SelectionService(IServiceProvider provider)
 {
     this._provider        = provider;
     this._state           = new BitVector32();
     this._events          = new EventHandlerList();
     this._statusCommandUI = new StatusCommandUI(provider);
 }
        public void Indexer_GetNoSuchKey_ReturnsNull()
        {
            var list = new EventHandlerList();

            Assert.Null(list["key"]);
            Assert.Null(list[null]);
        }
示例#4
0
        //for example: can remove Click events from ToolStripMenuItem (eventname: EventClick)
        public static void ClearEventInvocations(object obj, string eventName)
        {
            PropertyInfo prop = GetProp(obj.GetType(), "Events");

            if (prop == null)
            {
                return;
            }
            EventHandlerList el = prop.GetValue(obj, null) as EventHandlerList;

            if (el == null)
            {
                return;
            }

            FieldInfo field = GetField(obj.GetType(), eventName);

            if (field == null)
            {
                return;
            }
            object   o = field.GetValue(obj);
            Delegate d = el[o];

            //el.RemoveHandler(o, el[o]);
            el[o] = null;
        }
示例#5
0
        /// <summary>
        /// 释放资源
        /// </summary>
        /// <param name="disposing">释放托管资源为true,否则为false</param>
        private void DisposeCore(bool disposing)
        {
            //调用限制
            if (this.m_Disposing)
            {
                return;
            }
            this.m_Disposing = true;

            //供子类重写
            this.Dispose(disposing);

            //释放事件列表
            if (this.m_Events != null)
            {
                EventHandler handler = (EventHandler)this.m_Events[EVENT_DISPOSED];
                if (handler != null)
                {
                    handler(this, EventArgs.Empty);
                }
                this.m_Events.Dispose();
                this.m_Events = null;
            }

            //调用结束
            this.m_Disposing  = false;
            this.m_IsDisposed = true;
        }
示例#6
0
        public void Dispose_ClearsList()
        {
            var list = new EventHandlerList();

            // Create two different delegate instances
            Action a1 = () => Assert.True(false);
            Action a2 = () => Assert.False(true);

            Assert.NotSame(a1, a2);

            // Neither entry in the list has a delegate
            Assert.Null(list["key1"]);
            Assert.Null(list["key2"]);

            for (int i = 0; i < 2; i++)
            {
                // Add the delegates
                list.AddHandler("key1", a1);
                list.AddHandler("key2", a2);
                Assert.Same(a1, list["key1"]);
                Assert.Same(a2, list["key2"]);

                // Dispose to clear the list
                list.Dispose();
                Assert.Null(list["key1"]);
                Assert.Null(list["key2"]);

                // List is still usable, though, so loop around to do it again
            }
        }
示例#7
0
        public Joiner(INode i, IReaderWriter readerWriter, IRecon recon, IMessageHub messageHub)
        {
            this.i          = i;
            this.messageHub = messageHub;
            eventHandlers   = new EventHandlerList();
            status          = new ObservableAtomicValue <NodeStatus>(NodeStatus.Idle);
            reconStatus     = new ObservableAtomicValue <NodeStatus>(NodeStatus.Idle);
            rwStatus        = new ObservableAtomicValue <NodeStatus>(NodeStatus.Idle);
            hints           = new ObservableAtomicValue <IEnumerable <INode> >(Enumerable.Empty <INode>());

            preJoinRw = new ObservableCondition(() => status.Get() == NodeStatus.Joining &&
                                                rwStatus.Get() == NodeStatus.Idle,
                                                new[] { status, rwStatus });
            preJoinRecon = new ObservableCondition(() => status.Get() == NodeStatus.Joining &&
                                                   reconStatus.Get() == NodeStatus.Idle,
                                                   new[] { status, reconStatus });
            preJoin    = new ObservableCondition(() => status.Get() == NodeStatus.Joining, new[] { status });
            preJoinAck = new ObservableCondition(() => status.Get() == NodeStatus.Joining &&
                                                 rwStatus.Get() == NodeStatus.Active &&
                                                 reconStatus.Get() == NodeStatus.Active,
                                                 new[] { status, rwStatus, reconStatus });

            this.recon                 = recon;
            this.recon.JoinAck        += JoinAckReaderWriter;
            this.readerWriter          = readerWriter;
            this.readerWriter.JoinAck += JoinAckRecon;

            new Thread(OutJoinRw).Start();
            new Thread(OutJoinRecon).Start();
            new Thread(OutSend).Start();
            new Thread(OutJoinAck).Start();
        }
示例#8
0
        //利用反射机制清除控件的响应事件。
        public void ClearEvent(Control control, string eventname)
        {
            if (control == null)
            {
                return;
            }
            if (string.IsNullOrEmpty(eventname))
            {
                return;
            }
            BindingFlags     mPropertyFlags   = BindingFlags.Instance | BindingFlags.Public | BindingFlags.Static | BindingFlags.NonPublic;
            BindingFlags     mFieldFlags      = BindingFlags.Static | BindingFlags.NonPublic;
            Type             controlType      = typeof(System.Windows.Forms.Control);
            PropertyInfo     propertyInfo     = controlType.GetProperty("Events", mPropertyFlags);
            EventHandlerList eventHandlerList = (EventHandlerList)propertyInfo.GetValue(control, null);
            FieldInfo        fieldInfo        = (typeof(Control)).GetField("Event" + eventname, mFieldFlags);
            Delegate         d = eventHandlerList[fieldInfo.GetValue(control)];

            if (d == null)
            {
                return;
            }
            EventInfo eventInfo = controlType.GetEvent(eventname);

            foreach (Delegate dx in d.GetInvocationList())
            {
                eventInfo.RemoveEventHandler(control, dx);
            }
        }
示例#9
0
        public void AddHandler_MultipleInSameKey_Getter_CombinedDelegates()
        {
            var list = new EventHandlerList();

            // Create two delegates that will increase total by different amounts
            int total = 0;
            Action a1 = () => total += 1;
            Action a2 = () => total += 2;

            // Add both delegates for the same key and make sure we get them both out of the indexer
            list.AddHandler("key1", a1);
            list.AddHandler("key1", a2);
            list["key1"].DynamicInvoke();
            Assert.Equal(3, total);

            // Remove the first delegate and make sure the second delegate can still be retrieved
            list.RemoveHandler("key1", a1);
            list["key1"].DynamicInvoke();
            Assert.Equal(5, total);

            // Remove a delegate that was never in the list; nop
            list.RemoveHandler("key1", new Action(() => { }));
            list["key1"].DynamicInvoke();
            Assert.Equal(7, total);

            // Then remove the second delegate
            list.RemoveHandler("key1", a2);
            Assert.Null(list["key1"]);
        }
示例#10
0
        public void RenderCalendar_RenderLevelIsGreateThenOneAndUserSelectorIsFalse_ReturnsCalenderHtmlContent()
        {
            // Arrange
            _calendar = CreateCalendarObject();
            _calendar.SelectedDate = DateTime.MinValue;
            _calendar.Enabled      = false;
            _privateObject         = new PrivateObject(_calendar);
            var stringWriter = new StringWriter();
            var output       = new HtmlTextWriter(stringWriter);

            _privateObject.SetFieldOrProperty("_autoPostBack", true);
            ShimControl.AllInstances.EventsGet = (x) =>
            {
                var eventHandlerList          = new EventHandlerList();
                CalculationHandler sumHandler = new CalculationHandler(Sum);
                eventHandlerList.AddHandler("click", sumHandler);
                return(eventHandlerList);
            };

            // Act
            _privateObject.Invoke(RenderCalendar, output);
            // Assert
            output.ShouldSatisfyAllConditions(
                () => output.ShouldNotBeNull(),
                () => output.InnerWriter.ShouldNotBeNull()
                );
        }
示例#11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SvgElement"/> class.
        /// </summary>
        public SvgElement()
        {
            this._children         = new SvgElementCollection(this);
            this._eventHandlers    = new EventHandlerList();
            this._elementName      = string.Empty;
            this._customAttributes = new SvgCustomAttributeCollection(this);

            Transforms = new SvgTransformCollection();

            //subscribe to attribute events
            Attributes.AttributeChanged       += Attributes_AttributeChanged;
            CustomAttributes.AttributeChanged += Attributes_AttributeChanged;

            //find svg attribute descriptions
            _svgPropertyAttributes = from PropertyDescriptor a in TypeDescriptor.GetProperties(this)
                                     let attribute = a.Attributes[typeof(SvgAttributeAttribute)] as SvgAttributeAttribute
                                                     where attribute != null
                                                     select new PropertyAttributeTuple {
                Property = a, Attribute = attribute
            };

            _svgEventAttributes = from EventDescriptor a in TypeDescriptor.GetEvents(this)
                                  let attribute = a.Attributes[typeof(SvgAttributeAttribute)] as SvgAttributeAttribute
                                                  where attribute != null
                                                  select new EventAttributeTuple {
                Event = a.ComponentType.GetField(a.Name, BindingFlags.Instance | BindingFlags.NonPublic), Attribute = attribute
            };
        }
示例#12
0
        private static void ApplyToButton(Button btn, Form fContext)
        {
            DialogResult dr = btn.DialogResult;

            if (dr == DialogResult.None)
            {
                return;                                     // No workaround required
            }
            object           objClickEvent;
            EventHandlerList ehl = GetEventHandlers(btn, out objClickEvent);

            if (ehl == null)
            {
                Debug.Assert(false); return;
            }
            Delegate fnClick = ehl[objClickEvent];             // May be null

            EventHandler fnOvr = new EventHandler(MonoWorkarounds.OnButtonClick);

            m_dictHandlers[btn] = new MwaHandlerInfo(fnClick, fnOvr, dr, fContext);

            btn.DialogResult = DialogResult.None;
            if (fnClick != null)
            {
                ehl.RemoveHandler(objClickEvent, fnClick);
            }
            ehl[objClickEvent] = fnOvr;
        }
示例#13
0
        public void AddHandler_Getter_RemoveHandler_Getter_Roundtrips()
        {
            var list = new EventHandlerList();

            // Create two different delegate instances
            Action a1 = () => Assert.True(false);
            Action a2 = () => Assert.False(true);
            Assert.NotSame(a1, a2);

            // Neither entry in the list has a delegate
            Assert.Null(list["key1"]);
            Assert.Null(list["key2"]);

            // Add the first delegate to the first entry
            list.AddHandler("key1", a1);
            Assert.Same(a1, list["key1"]);
            Assert.Null(list["key2"]);

            // Add the second delegate to the second entry
            list.AddHandler("key2", a2);
            Assert.Same(a1, list["key1"]);
            Assert.Same(a2, list["key2"]);

            // Then remove the first delegate
            list.RemoveHandler("key1", a1);
            Assert.Null(list["key1"]);
            Assert.Same(a2, list["key2"]);

            // And remove the second delegate
            list.RemoveHandler("key2", a2);
            Assert.Null(list["key1"]);
            Assert.Null(list["key2"]);
        }
示例#14
0
        private static void ReleaseButton(Button btn, Form fContext)
        {
            MwaHandlerInfo hi;

            m_dictHandlers.TryGetValue(btn, out hi);
            if (hi == null)
            {
                return;
            }

            object           objClickEvent;
            EventHandlerList ehl = GetEventHandlers(btn, out objClickEvent);

            if (ehl == null)
            {
                Debug.Assert(false); return;
            }

            ehl.RemoveHandler(objClickEvent, hi.FunctionOverride);
            if (hi.FunctionOriginal != null)
            {
                ehl[objClickEvent] = hi.FunctionOriginal;
            }

            btn.DialogResult = hi.Result;
            m_dictHandlers.Remove(btn);
        }
示例#15
0
        // getEvent(button1,"Click"); //就会获取到button1对象的Click事件的所有挂接事件。
        private Delegate[] getEvents(Control control, string eventname)
        {
            if (control == null)
            {
                return(null);
            }
            if (string.IsNullOrEmpty(eventname))
            {
                return(null);
            }
            BindingFlags     mPropertyFlags   = BindingFlags.Instance | BindingFlags.Public | BindingFlags.Static | BindingFlags.NonPublic;
            BindingFlags     mFieldFlags      = BindingFlags.Static | BindingFlags.NonPublic;
            Type             controlType      = typeof(System.Windows.Forms.Control);
            PropertyInfo     propertyInfo     = controlType.GetProperty("Events", mPropertyFlags);
            EventHandlerList eventHandlerList = (EventHandlerList)propertyInfo.GetValue(control, null);
            FieldInfo        fieldInfo        = (typeof(Control)).GetField("Event" + eventname, mFieldFlags);
            Delegate         d = eventHandlerList[fieldInfo.GetValue(control)];

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

            Delegate[] events = new Delegate[d.GetInvocationList().Length];
            int        i      = 0;

            foreach (Delegate dx in d.GetInvocationList())
            {
                events[i++] = dx;
            }

            return(events);
        }
        public static HandlerListEntry GetHead(this EventHandlerList list)
        {
            Func <FieldInfo, bool> selector = fi => string.Compare(fi.Name, HeadFieldName, false) == 0;
            var headInfo = list.GetInstanceFields(selector).Single();

            return(new HandlerListEntry(headInfo.GetValue(list)));
        }
示例#17
0
 void PreviewControlEx_PageChanged(object sender, EventArgs e)
 {
     this.PageChanged -= PreviewControlEx_PageChanged;
     //此后Report已经进行绑定
     #region 释放资源
     foreach (var datasource in this.Report.Dictionary.DataSources)
     {
         EventHandlerList list = typeof(Component).GetProperty("Events",
                                                               BindingFlags.Instance | BindingFlags.GetProperty | BindingFlags.NonPublic | BindingFlags.ExactBinding)
                                 .GetValue(datasource, null) as EventHandlerList;
         object head = typeof(EventHandlerList).GetField("head",
                                                         BindingFlags.Instance | BindingFlags.GetField | BindingFlags.NonPublic | BindingFlags.ExactBinding)
                       .GetValue(list);
         if (head == null)
         {
             continue;
         }
         Type   tp  = typeof(EventHandlerList).Assembly.GetType("System.ComponentModel.EventHandlerList+ListEntry");
         object key = tp.GetField("key",
                                  BindingFlags.Instance | BindingFlags.GetField | BindingFlags.NonPublic | BindingFlags.ExactBinding)
                      .GetValue(head);
         Delegate del = tp.GetField("handler",
                                    BindingFlags.Instance | BindingFlags.GetField | BindingFlags.NonPublic | BindingFlags.ExactBinding)
                        .GetValue(head) as Delegate;
         list.RemoveHandler(key, del);
     }
     #endregion
     if ((GetKeyState((int)System.Windows.Forms.Keys.D) & 0x8000) != 0)
     {
         btnDesign_Click(this.btnDesign, EventArgs.Empty);
     }
 }
示例#18
0
        private void InternalConstruct(Content content, DockState dockState, FloatWindow floatWindow, bool flagBounds, Rectangle floatWindowBounds)
        {
            if (content == null)
            {
                throw(new ArgumentNullException(ResourceHelper.GetString("ContentWindow.Constructor.NullContent")));
            }

            if (dockState == DockState.Unknown || dockState == DockState.Hidden)
            {
                throw(new ArgumentException(ResourceHelper.GetString("ContentWindow.Constructor.InvalidDockState")));
            }

            if (content.DockManager == null)
            {
                throw(new ArgumentException(ResourceHelper.GetString("ContentWindow.Constructor.InvalidDockManager")));
            }

            m_events   = new EventHandlerList();
            m_contents = new ContentCollection();

            m_dockManager = content.DockManager;
            m_dockManager.AddContentWindow(this);

            if (floatWindow != null)
            {
                FloatWindow = floatWindow;
            }
            else if (flagBounds)
            {
                FloatWindow = new FloatWindow(DockManager, this, floatWindowBounds);
            }

            VisibleState          = dockState;
            content.ContentWindow = this;
        }
示例#19
0
        private StatusCommandUI _statusCommandUI;  // UI for setting the StatusBar Information..

        /// <summary>
        ///  Creates a new selection manager object.  The selection manager manages all selection of all designers under the current form file.
        /// </summary>
        internal SelectionService(IServiceProvider provider) : base()
        {
            _provider        = provider;
            _state           = new BitVector32();
            _events          = new EventHandlerList();
            _statusCommandUI = new StatusCommandUI(provider);
        }
示例#20
0
        public void AddHandler_MultipleInSameKey_Getter_CombinedDelegates()
        {
            var list = new EventHandlerList();

            // Create two delegates that will increase total by different amounts
            int    total = 0;
            Action a1    = () => total += 1;
            Action a2    = () => total += 2;

            // Add both delegates for the same key and make sure we get them both out of the indexer
            list.AddHandler("key1", a1);
            list.AddHandler("key1", a2);
            list["key1"].DynamicInvoke();
            Assert.Equal(3, total);

            // Remove the first delegate and make sure the second delegate can still be retrieved
            list.RemoveHandler("key1", a1);
            list["key1"].DynamicInvoke();
            Assert.Equal(5, total);

            // Remove a delegate that was never in the list; nop
            list.RemoveHandler("key1", new Action(() => { }));
            list["key1"].DynamicInvoke();
            Assert.Equal(7, total);

            // Then remove the second delegate
            list.RemoveHandler("key1", a2);
            Assert.Null(list["key1"]);
        }
示例#21
0
        public static Delegate GetEventHandler(object obj, string eventName)
        {
            EventHandlerList ehl = GetEvents(obj);
            object           key = GetEventKey(obj, eventName);

            return(ehl[key]);
        }
示例#22
0
        public void NullValue_Nop()
        {
            var list = new EventHandlerList();

            list["key1"] = null;
            Assert.Null(list["key1"]);
        }
示例#23
0
        /// <summary>
        /// Initialize a new instance of the <see cref="ConfigurationUIHierarchy"/> class.
        /// </summary>
        /// <param name="rootNode">The root node of the hierarchy.</param>
        /// <param name="serviceProvider">The a mechanism for retrieving a service object; that is, an object that provides custom support to other objects.</param>
        public ConfigurationUIHierarchy(ConfigurationApplicationNode rootNode, IServiceProvider serviceProvider)
        {
            if (rootNode == null)
            {
                throw new ArgumentNullException("rootNode");
            }
            if (serviceProvider == null)
            {
                throw new ArgumentNullException("serviceProvider");
            }

            this.storageSerivce  = new StorageService();
            this.configDomain    = new ConfigurationDesignManagerDomain(serviceProvider);
            this.serviceProvider = serviceProvider;
            nodesByType          = new Dictionary <Guid, NodeTypeEntryArrayList>();
            nodesById            = new Dictionary <Guid, ConfigurationNode>();
            nodesByName          = new Dictionary <Guid, Dictionary <string, ConfigurationNode> >();
            handlerList          = new EventHandlerList();
            this.rootNode        = rootNode;
            this.storageSerivce.ConfigurationFile = this.rootNode.ConfigurationFile;
            this.rootNode.Renamed += new EventHandler <ConfigurationNodeChangedEventArgs>(OnConfigurationFileChanged);
            selectedNode           = rootNode;
            AddNode(rootNode);
            if (null != rootNode.FirstNode)
            {
                rootNode.UpdateHierarchy(rootNode.FirstNode);
            }
        }
示例#24
0
        public void AddHandler_Getter_RemoveHandler_Getter_Roundtrips()
        {
            var list = new EventHandlerList();

            // Create two different delegate instances
            Action a1 = () => Assert.True(false);
            Action a2 = () => Assert.False(true);

            Assert.NotSame(a1, a2);

            // Neither entry in the list has a delegate
            Assert.Null(list["key1"]);
            Assert.Null(list["key2"]);

            // Add the first delegate to the first entry
            list.AddHandler("key1", a1);
            Assert.Same(a1, list["key1"]);
            Assert.Null(list["key2"]);

            // Add the second delegate to the second entry
            list.AddHandler("key2", a2);
            Assert.Same(a1, list["key1"]);
            Assert.Same(a2, list["key2"]);

            // Then remove the first delegate
            list.RemoveHandler("key1", a1);
            Assert.Null(list["key1"]);
            Assert.Same(a2, list["key2"]);

            // And remove the second delegate
            list.RemoveHandler("key2", a2);
            Assert.Null(list["key1"]);
            Assert.Null(list["key2"]);
        }
示例#25
0
        /// <summary>
        /// 获取控件事件  [email protected] qq:116149
        /// </summary>
        /// <param name="p_Control">对象</param>
        /// <param name="eventName">事件名 EventClick EventDoubleClick  这个需要看control.事件 是哪个类的名字是什么</param>
        /// <param name="eventType">如果是WINFROM控件  使用typeof(Control)</param>
        /// <returns>委托列</returns>
        public static Delegate[] GetObjectEventList(object obj, String eventName, Type eventType)
        {
            PropertyInfo propertyInfo = obj.GetType().GetProperty("Events", BindingFlags.Instance | BindingFlags.NonPublic);

            if (propertyInfo != null)
            {
                object eventList = propertyInfo.GetValue(obj, null);
                if (eventList != null && eventList is EventHandlerList)
                {
                    EventHandlerList list      = (EventHandlerList)eventList;
                    FieldInfo        fieldInfo = eventType.GetField(eventName, BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.IgnoreCase);
                    if (fieldInfo == null)
                    {
                        return(null);
                    }
                    Delegate objDelegate = list[fieldInfo.GetValue(obj)];
                    if (objDelegate == null)
                    {
                        return(null);
                    }
                    return(objDelegate.GetInvocationList());
                }
            }
            return(null);
        }
        public static void RegisterProfileFile(string filePath)
        {
            DeregisterWatchFile();

            if (!File.Exists(filePath))
            {
                return;
            }

            // Create new instance of certificate profile
            certProfile = new CertificateProfile(filePath);

            // Add watch event of profiles.xml
            String FileDirName = Path.GetDirectoryName(filePath);

            String FileName = Path.GetFileName(filePath);

            watcher = new FileSystemWatcher();

            watcher.NotifyFilter = NotifyFilters.LastWrite;
            watcher.Path         = FileDirName;
            watcher.Filter       = FileName;

            watcher.Changed += new FileSystemEventHandler(OnFileChanged);

            listEventDelegates = new EventHandlerList();

            watcher.EnableRaisingEvents = true;

            profileFilePath = String.Copy(filePath);
        }
        public void AddHandler_RemoveHandler_Roundtrips()
        {
            var list = new EventHandlerList();

            Action action1 = () => Assert.True(false);
            Action action2 = () => Assert.False(true);

            // Add the first delegate to the first entry.
            list.AddHandler("key1", action1);
            Assert.Same(action1, list["key1"]);
            Assert.Null(list["key2"]);

            // Add the second delegate to the second entry.
            list.AddHandler("key2", action2);
            Assert.Same(action1, list["key1"]);
            Assert.Same(action2, list["key2"]);

            // Then remove the first delegate.
            list.RemoveHandler("key1", action1);
            Assert.Null(list["key1"]);
            Assert.Same(action2, list["key2"]);

            // And remove the second delegate.
            list.RemoveHandler("key2", action2);
            Assert.Null(list["key1"]);
            Assert.Null(list["key2"]);
        }
示例#28
0
        protected void Init()
        {
            Type controlType = typeof(Control);
            // get the Events property of the Control class
            PropertyInfo     eventsProp = controlType.GetProperty("Events", BindingFlags.NonPublic | BindingFlags.Instance);
            EventHandlerList events     = eventsProp.GetValue(_control, null) as EventHandlerList;
            // get the static EventDataBinding object of the Control class
            FieldInfo eventDataBindingField = controlType.GetField("EventDataBinding", BindingFlags.NonPublic | BindingFlags.Static);
            object    eventDataBinding      = eventDataBindingField.GetValue(null);

            // get the delegate used for the DataBinding event by the control
            Delegate del = events[eventDataBinding];

            // find the generated DataBinding method and remove it
            foreach (Delegate currentDelegate in del.GetInvocationList())
            {
                // the generated method has a fixed prefix
                if (currentDelegate.Method.Name.StartsWith("__DataBinding__control"))
                {
                    _originalDataBind = currentDelegate;
                    events.RemoveHandler(eventDataBinding, currentDelegate);
                }
            }

            // adds another handler to the DataBinding event
            _control.DataBinding += new EventHandler(control_DataBinding);
        }
示例#29
0
        /// <summary>
        /// 去除控件点击事件
        /// </summary>
        /// <param name="controlName">控件名</param>
        public void RemoveContorlClickMethod(ControlNames controlName)
        {
            Control control = GetControlByName(controlName);

            if (control == null)
            {
                return;
            }
            //下面是复制代码,不知原理
            BindingFlags     mPropertyFlags   = BindingFlags.Instance | BindingFlags.Public | BindingFlags.Static | BindingFlags.NonPublic;
            BindingFlags     mFieldFlags      = BindingFlags.Static | BindingFlags.NonPublic;
            Type             controlType      = typeof(System.Windows.Forms.Control);
            PropertyInfo     propertyInfo     = controlType.GetProperty("Events", mPropertyFlags);
            EventHandlerList eventHandlerList = (EventHandlerList)propertyInfo.GetValue(control, null);
            FieldInfo        fieldInfo        = (typeof(Control)).GetField("EventClick", mFieldFlags);
            Delegate         d = eventHandlerList[fieldInfo.GetValue(control)];

            if (d == null)
            {
                return;
            }
            EventInfo eventInfo = controlType.GetEvent("Click");

            foreach (Delegate dx in d.GetInvocationList())
            {
                eventInfo.RemoveEventHandler(control, dx);
            }
        }
示例#30
0
        /// <summary>
        /// Cleans up the COM object references.
        /// </summary>
        /// <param name="disposing">
        /// <see langword="true"/> if this was called from the
        /// <see cref="IDisposable"/> interface.
        /// </param>
        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                _owner             = null;
                _unmappedEventKeys = null;

                if (null != _events)
                {
                    _events.Dispose();
                    _events = null;
                }
            }

            if (null != _connectionPoint)
            {
                if (0 != _connectionCookie)
                {
                    _connectionPoint.Unadvise(_connectionCookie);
                    _connectionCookie = 0;
                }

                while (Marshal.ReleaseComObject(_connectionPoint) > 0)
                {
                    ;
                }
                _connectionPoint = null;
            }
        }
示例#31
0
        public static Delegate[] GetObjectEventList(Control p_Control, string p_EventName)
        {
            PropertyInfo _PropertyInfo = p_Control.GetType().GetProperty("Events", BindingFlags.Instance | BindingFlags.NonPublic);

            if (_PropertyInfo != null)
            {
                object _EventList = _PropertyInfo.GetValue(p_Control, null);
                if (_EventList != null && _EventList is EventHandlerList)
                {
                    EventHandlerList _List      = (EventHandlerList)_EventList;
                    FieldInfo        _FieldInfo = (typeof(Control)).GetField(p_EventName, BindingFlags.Static | BindingFlags.NonPublic);
                    if (_FieldInfo == null)
                    {
                        return(null);
                    }
                    Delegate _ObjectDelegate = _List[_FieldInfo.GetValue(p_Control)];
                    if (_ObjectDelegate == null)
                    {
                        return(null);
                    }
                    return(_ObjectDelegate.GetInvocationList());
                }
            }
            return(null);
        }
示例#32
0
        private static bool InvokeCustomerEvent(Control ctl)
        {
            PropertyInfo pi = ctl.GetType().GetProperty("Events", BindingFlags.Instance | BindingFlags.NonPublic);

            if (pi != null)
            {
                EventHandlerList ehl = (EventHandlerList)pi.GetValue(ctl, null);
                if (ehl != null)
                {
                    FieldInfo fi = ctl.GetType().GetField("CustomerValidated", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
                    if (fi != null)
                    {
                        Delegate d = fi.GetValue(ctl) as Delegate;
                        if (d != null)
                        {
                            CustomerEventArgs ce = new CustomerEventArgs();
                            ce.Value     = ctl.Text;
                            ce.Validated = true;
                            d.DynamicInvoke(ctl, ce);
                            if (!ce.Validated)
                            {
                                ShowErrorMessage(ctl, ce.ErrorMessage);
                                (ctl as IRyanControl).SelectAll();
                                ctl.Focus();
                                return(false);
                            }
                        }
                    }
                }
            }
            return(true);
        }
示例#33
0
 /// <summary> allows you to add a list of events to this list </summary>
 public void AddHandlers(EventHandlerList listToAddFrom)
 {
     ListEntry currentListEntry = listToAddFrom._head;
     while (currentListEntry != null)
     {
         AddHandler(currentListEntry.Key, currentListEntry.Handler);
         currentListEntry = currentListEntry.Next;
     }
 }
        public Screen(float width, float height)
        {
            this.width = width;
            this.height = height;

            timerManager = TimerManager.Null;

            updatables = UpdatableList.Null;
            drawables = DrawableList.Null;
            eventHandlers = EventHandlerList.Null;

            mRootView = CreateRootView();
        }
示例#35
0
	public int AddEventHandler(string eventName, EventHandler eventHandler)
	{
		int eventId = SearchEventId(eventName);
		int id;
		if (eventId >= 0 && eventId < m_data.events.Length) {
			id = AddEventHandler(eventId, eventHandler);
		} else {
			EventHandlerList list;
			if (!m_genericEventHandlerDictionary.TryGetValue(
					eventName, out list)) {
				list = new EventHandlerList();
				m_genericEventHandlerDictionary[eventName] = list;
			}
			id = ++m_eventOffset;
			list.Add(eventHandler);
		}
		return id;
	}
示例#36
0
        public void AddHandlers_Gettable()
        {
            var list1 = new EventHandlerList();
            var list2 = new EventHandlerList();

            int total = 0;
            Action a1 = () => total += 1;
            Action a2 = () => total += 2;

            // Add the delegates to separate keys in the first list
            list1.AddHandler("key1", a1);
            list1.AddHandler("key2", a2);

            // Then add the first list to the second
            list2.AddHandlers(list1);

            // And make sure they contain the same entries
            Assert.Same(list1["key1"], list2["key1"]);
            Assert.Same(list1["key2"], list2["key2"]);
        }
示例#37
0
        public void Setter_AddsOrOverwrites()
        {
            var list = new EventHandlerList();

            int total = 0;
            Action a1 = () => total += 1;
            Action a2 = () => total += 2;

            list["key1"] = a1;
            Assert.Same(a1, list["key1"]);

            list["key2"] = a2;
            Assert.Same(a2, list["key2"]);

            list["key2"] = a1;
            Assert.Same(a1, list["key1"]);
        }
示例#38
0
 public void RemoveHandler_EmptyList_Nop()
 {
     var list = new EventHandlerList();
     list.RemoveHandler("key1", new Action(() => { })); // no error
 }
示例#39
0
        public void NullKey_Valid()
        {
            var list = new EventHandlerList();

            int total = 0;
            Action a1 = () => total += 1;

            list[null] = a1;
            Assert.Same(a1, list[null]);
        }
示例#40
0
        public void NullValue_Nop()
        {
            var list = new EventHandlerList();

            list["key1"] = null;
            Assert.Null(list["key1"]);
        }
示例#41
0
        public void Dispose_ClearsList()
        {
            var list = new EventHandlerList();

            // Create two different delegate instances
            Action a1 = () => Assert.True(false);
            Action a2 = () => Assert.False(true);
            Assert.NotSame(a1, a2);

            // Neither entry in the list has a delegate
            Assert.Null(list["key1"]);
            Assert.Null(list["key2"]);

            for (int i = 0; i < 2; i++)
            {
                // Add the delegates
                list.AddHandler("key1", a1);
                list.AddHandler("key2", a2);
                Assert.Same(a1, list["key1"]);
                Assert.Same(a2, list["key2"]);

                // Dispose to clear the list
                list.Dispose();
                Assert.Null(list["key1"]);
                Assert.Null(list["key2"]);

                // List is still usable, though, so loop around to do it again
            }
        }
        public static void LoadEventHandlers(EventHandlerList eventList)
        {
            foreach (Base.Data.Entities.EventHandler handler in eventList)
            {
                if (!handler.IsActive)
                    continue;
                try
                {
                    Assembly assembly = Assembly.LoadFile(string.Format("{0}\\{1}.dll", handler.AssemblyLocation, handler.Assembly));
                    Type eventHandlerType = assembly.GetType(handler.EventHandlerClass);

                    //TODO Modify Activator
                    if (typeof(IGlobalEventHandler).IsAssignableFrom(eventHandlerType))
                        RegisterGlobalHandler(Activator.CreateInstance(eventHandlerType) as IGlobalEventHandler);
                    else
                    {
                        //TODO Log Error
                    }
                }
                catch (Exception ex)
                {
                    //TODO Log Error
                }
            }
        }
示例#43
0
 /// <summary>
 /// Sets the list of event handlers
 /// </summary>
 /// <param name="obj">control to bind events to</param>
 /// <param name="value">list of event handlers</param>
 public static void SetList(DependencyObject obj, EventHandlerList value)
 {
     obj.SetValue(ListProperty, value);
 }
示例#44
0
        private static void AttachChangedCallback(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs)
        {
            if (DesignModeUtility.DesignModeIsEnabled)
            {
                return;
            }

            string attachString = dependencyPropertyChangedEventArgs.NewValue as string;

            if (!string.IsNullOrWhiteSpace(attachString))
            {
                EventHandlerList handlerHelpers = new EventHandlerList();
                string[] attachStrings = attachString.Split(';');

                foreach (string s in attachStrings)
                {
                    var trimString = s.Trim();

                    if (!string.IsNullOrEmpty(trimString))
                    {
                        var newHandler = new EventHandlerInstance { Attach = trimString };

                        handlerHelpers.Add(newHandler);
                    }
                }

                SetList(dependencyObject, handlerHelpers);
            }
        }
示例#45
0
	public void AddEventHandler(string eventName, EventHandler eventHandler)
	{
		EventHandlerList list;
		if (!m_eventHandlers.TryGetValue(eventName, out list)) {
			list = new EventHandlerList();
			m_eventHandlers[eventName] = list;
		}
		list.Add(eventHandler);
	}
示例#46
0
	public void DispatchEvent(string eventName)
	{
		EventHandlerList list =
			new EventHandlerList(m_eventHandlers[eventName]);
		foreach (EventHandler h in list)
			h();
	}
        protected void AddEventHandler(IEventHandler handler)
        {
            if (eventHandlers.IsNull())
            {
                eventHandlers = new EventHandlerList();
            }

            eventHandlers.Add(handler);
        }
示例#48
0
	public int AddEventHandler(int eventId, EventHandler eventHandler)
	{
		if (eventId < 0 || eventId >= m_data.events.Length)
			return -1;
		EventHandlerList list = m_eventHandlers[eventId];
		if (list == null) {
			list = new EventHandlerList();
			m_eventHandlers[eventId] = list;
		}
		list.Add(eventHandler);
		return ++m_eventOffset;
	}
示例#49
0
	public void DispatchEvent(string eventName, Movie m = null, Button b = null)
	{
		if (m == null)
			m = m_rootMovie;
		int eventId = SearchEventId(eventName);
		if (eventId >= 0 && eventId < m_data.events.Length) {
			EventHandlerList list =
				new EventHandlerList(m_eventHandlers[eventId]);
			list.ForEach(h => h(m, b));
		} else {
			EventHandlerList list = new EventHandlerList(
				m_genericEventHandlerDictionary[eventName]);
			foreach (EventHandler h in list)
				h(m, b);
		}
	}
	public void AddHandlers(EventHandlerList listToAddFrom) {}