當前位置: 首頁>>代碼示例>>C#>>正文


C# EventHandler.ToString方法代碼示例

本文整理匯總了C#中EventHandler.ToString方法的典型用法代碼示例。如果您正苦於以下問題:C# EventHandler.ToString方法的具體用法?C# EventHandler.ToString怎麽用?C# EventHandler.ToString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在EventHandler的用法示例。


在下文中一共展示了EventHandler.ToString方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: hookDelegate

        /// <summary>
        /// hook delegate
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="target"></param>
        /// <param name="eventname"></param>
        /// <param name="functionname"></param>
        public static void hookDelegate(object sender, EventHandler handler, String eventname, String multi1, String multi2)
        {
            if (sender == null)
            {
                throw new ArgumentNullException("sender");
            }

            if (handler == null)
            {
                throw new ArgumentNullException("handler");
            }

            try
            {
                EventInfo evClick = sender.GetType().GetEvent(eventname);

                //check if a delegate is already hooked
                if (multi1.Equals("Single",StringComparison.OrdinalIgnoreCase))
                {
                    FieldInfo fi = sender.GetType().GetField(eventname, BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public | BindingFlags.FlattenHierarchy);
                    if (fi != null)
                    {
                        Delegate del = (Delegate)fi.GetValue(sender);
                        if (del != null)
                        {
                            if (del.GetInvocationList().Length > 0)
                            {
                                return;
                            }
                        }
                    }
                }

                MethodInfo addHandler = evClick.GetAddMethod();
                Object[] addHandlerArgs = { handler };
                addHandler.Invoke(sender, addHandlerArgs);
            }
            catch (Exception ex)
            {
                //log.Error(ex);
                //throw ex; //TODO make some logging and dont throw
                throw new Exception("Error in hookDelegate: " + eventname + " - " + " - " + sender.ToString() + " - " + handler.ToString() + " - "  + ex.Message);
            }
        }
開發者ID:sharpend,項目名稱:Sharpend,代碼行數:51,代碼來源:Reflection.cs

示例2: ReturnFriendlyDescription

            public void ReturnFriendlyDescription()
            {
                var eventHandler = new EventHandler(typeof(Object), typeof(FakeEvent), (h, e) => { }, () => new Object());

                Assert.Equal($"{typeof (FakeEvent)} Event Handler ({typeof (Object)})", eventHandler.ToString());
            }
開發者ID:SparkSoftware,項目名稱:infrastructure,代碼行數:6,代碼來源:EventHandlerTests.cs


注:本文中的EventHandler.ToString方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。