本文整理汇总了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);
}
}
示例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());
}