本文整理汇总了C#中System.Reflection.EventInfo类的典型用法代码示例。如果您正苦于以下问题:C# EventInfo类的具体用法?C# EventInfo怎么用?C# EventInfo使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
EventInfo类属于System.Reflection命名空间,在下文中一共展示了EventInfo类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
//引入命名空间
using System;
using System.Reflection;
using System.Security;
class MyEventExample
{
public static void Main()
{
try
{
// Creates a bitmask based on BindingFlags.
BindingFlags myBindingFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
Type myTypeBindingFlags = typeof(System.Windows.Forms.Button);
EventInfo myEventBindingFlags = myTypeBindingFlags.GetEvent("Click", myBindingFlags);
if(myEventBindingFlags != null)
{
Console.WriteLine("Looking for the Click event in the Button class with the specified BindingFlags.");
Console.WriteLine(myEventBindingFlags.ToString());
}
else
{
Console.WriteLine("The Click event is not available with the Button class.");
}
}
catch(SecurityException e)
{
Console.WriteLine("An exception occurred.");
Console.WriteLine("Message :"+e.Message);
}
catch(ArgumentNullException e)
{
Console.WriteLine("An exception occurred.");
Console.WriteLine("Message :"+e.Message);
}
catch(Exception e)
{
Console.WriteLine("The following exception was raised : {0}",e.Message);
}
}
}