本文整理汇总了C#中System.Reflection.EventInfo.GetOtherMethods方法的典型用法代码示例。如果您正苦于以下问题:C# EventInfo.GetOtherMethods方法的具体用法?C# EventInfo.GetOtherMethods怎么用?C# EventInfo.GetOtherMethods使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.EventInfo
的用法示例。
在下文中一共展示了EventInfo.GetOtherMethods方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DefineEvent
/// <summary>
/// Defines an event based on the specified event.
/// </summary>
/// <param name="typeBuilder">The type builder.</param>
/// <param name="eventInfo">The event information.</param>
/// <param name="isExplicit">A value indicating whether the specified event should be implemented explicitly.</param>
/// <param name="methodBuilderFactory">The method builder factory function.</param>
/// <returns>The event builder.</returns>
public static void DefineEvent(this TypeBuilder typeBuilder,
EventInfo eventInfo,
bool isExplicit,
Func<MethodInfo, bool, MethodBuilder> methodBuilderFactory)
{
if (typeBuilder == null)
throw new ArgumentNullException("typeBuilder");
if (eventInfo == null)
throw new ArgumentNullException("eventInfo");
if (methodBuilderFactory == null)
throw new ArgumentNullException("methodBuilderFactory");
// Define event.
var eventName = isExplicit ? eventInfo.GetFullName() : eventInfo.Name;
var eventBuilder = typeBuilder.DefineEvent(
eventName,
eventInfo.Attributes,
eventInfo.EventHandlerType);
// Build event add method.
var addMethodInfo = eventInfo.GetAddMethod();
var addMethodBuilder = methodBuilderFactory(addMethodInfo, isExplicit);
eventBuilder.SetAddOnMethod(addMethodBuilder);
// Build event remove method.
var removeMethodInfo = eventInfo.GetRemoveMethod(true);
var removeMethodBuilder = methodBuilderFactory(removeMethodInfo, isExplicit);
eventBuilder.SetRemoveOnMethod(removeMethodBuilder);
// Build event raise method.
var raiseMethodInfo = eventInfo.GetRaiseMethod(true);
if (raiseMethodInfo != null)
{
var methodBuilder = methodBuilderFactory(raiseMethodInfo, isExplicit);
eventBuilder.SetRaiseMethod(methodBuilder);
}
// Build event other methods.
var otherMethodInfos = eventInfo.GetOtherMethods(true);
// Mono returns null in case no other methods are defined.
if (otherMethodInfos != null)
{
foreach (var otherMethodInfo in otherMethodInfos)
{
var methodBuilder = methodBuilderFactory(otherMethodInfo, isExplicit);
eventBuilder.AddOtherMethod(methodBuilder);
}
}
}