本文整理汇总了C#中System.Reflection.EventInfo.GetRaiseMethod方法的典型用法代码示例。如果您正苦于以下问题:C# EventInfo.GetRaiseMethod方法的具体用法?C# EventInfo.GetRaiseMethod怎么用?C# EventInfo.GetRaiseMethod使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.EventInfo
的用法示例。
在下文中一共展示了EventInfo.GetRaiseMethod方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AreEquivalent
/// <summary>
/// Verifies that two events are equivalent.
/// </summary>
/// <param name="actual">The actual event information.</param>
/// <param name="expected">The expected event information.</param>
/// <param name="isExplicit">A value indicating whether the actual event is implemented explicitly.</param>
public static void AreEquivalent(EventInfo actual, EventInfo expected, bool isExplicit)
{
Assert.That(actual, Is.Not.Null);
Assert.That(expected, Is.Not.Null);
// Check member properties.
AreMembersEquivalent(actual, expected);
// Check event properties.
Assert.That(actual.Attributes, Is.EqualTo(expected.Attributes));
Assert.That(actual.IsMulticast, Is.EqualTo(expected.IsMulticast));
Assert.That(actual.IsSpecialName, Is.EqualTo(expected.IsSpecialName));
// Check event handler type.
AreTypesEquivalent(actual.EventHandlerType, expected.EventHandlerType);
// Check event methods.
InternalAreEquivalent(actual.GetAddMethod(), expected.GetAddMethod(), isExplicit);
InternalAreEquivalent(actual.GetRemoveMethod(), expected.GetRemoveMethod(), isExplicit);
InternalAreEquivalent(actual.GetRaiseMethod(), expected.GetRaiseMethod(), isExplicit);
}
示例2: RaiseEvent
public static bool RaiseEvent(object getInstance, PlTerm memberSpec, PlTerm[] paramIn, PlTerm valueOut,
EventInfo evi, Type c)
{
if (evi == null)
{
return Warn("Cant find event {0} on {1}", memberSpec, c);
}
ParameterInfo[] paramInfos = GetParmeters(evi);
MethodInfo mi = evi.GetRaiseMethod();
string fn = evi.Name;
if (mi == null)
{
FieldInfo fi = c.GetField(fn, BindingFlagsALLNC);
if (fi != null)
{
Delegate del = (Delegate) fi.GetValue(getInstance);
if (del != null)
{
Action postCallHook;
var ret = valueOut.FromObject((del.DynamicInvoke(
PlListToCastedArray(paramIn, paramInfos,
out postCallHook))));
CommitPostCall(postCallHook);
return ret;
}
}
string fn1 = fn.Substring(1);
int len = fn.Length;
foreach (FieldInfo info in c.GetFields(BindingFlagsALL))
{
if (info.Name.EndsWith(fn1))
{
if (info.Name.Length - len < 3)
{
Delegate del = (Delegate) info.GetValue(info.IsStatic ? null : getInstance);
if (del != null)
{
Action postCallHook;
var ret = valueOut.FromObject((del.DynamicInvoke(
PlListToCastedArray(paramIn, paramInfos,
out postCallHook))));
CommitPostCall(postCallHook);
return ret;
}
}
}
}
}
if (mi == null)
{
Type eviEventHandlerType = evi.EventHandlerType;
if (eviEventHandlerType != null) mi = eviEventHandlerType.GetMethod("Invoke");
}
if (mi == null)
{
Warn("Cant find event raising for {0} on {1}", evi, c);
return false;
}
Action postCallHook0;
object[] value = PlListToCastedArray(paramIn, mi.GetParameters(), out postCallHook0);
object target = mi.IsStatic ? null : getInstance;
return valueOut.FromObject(InvokeCaught(mi, target, value, postCallHook0) ?? VoidOrNull(mi));
}
示例3: GetParmeters
private static ParameterInfo[] GetParmeters(EventInfo ei)
{
ParameterInfo[] parme = null;
var rm = ei.GetRaiseMethod();
var erm = ei.EventHandlerType;
if (rm == null && erm != null)
{
rm = erm.GetMethod("Invoke");
}
if (rm != null)
{
parme = rm.GetParameters();
}
return parme;
}
示例4: 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();
var removeMethodBuilder = methodBuilderFactory(removeMethodInfo, isExplicit);
eventBuilder.SetRemoveOnMethod(removeMethodBuilder);
// Build event raise method.
var raiseMethodInfo = eventInfo.GetRaiseMethod();
if (raiseMethodInfo != null)
{
var methodBuilder = methodBuilderFactory(raiseMethodInfo, isExplicit);
eventBuilder.SetRaiseMethod(methodBuilder);
}
}
示例5: 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);
}
}
}
示例6: MapEvent
private void MapEvent(EventInfo evt, EventDefinition event_definition)
{
if (_options.EraseMember(evt)) return;
var type_definition = event_definition.DeclaringType;
var add = evt.GetAddMethod(nonPublic: true);
if (add != null)
{
event_definition.AddMethod = type_definition.Methods.Single(m => m.Name == add.Name);
event_definition.AddMethod.IsAddOn = true;
}
var remove = evt.GetRemoveMethod(nonPublic: true);
if (remove != null)
{
event_definition.RemoveMethod = type_definition.Methods.Single(m => m.Name == remove.Name);
event_definition.RemoveMethod.IsRemoveOn = true;
}
var raise = evt.GetRaiseMethod(nonPublic: true);
if (raise != null)
{
event_definition.InvokeMethod = type_definition.Methods.Single(m => m.Name == raise.Name);
event_definition.InvokeMethod.IsFire = true;
}
MapCustomAttributes(evt, event_definition);
}
示例7: BuildEvent
private void BuildEvent(EventInfo eventInfo)
{
EventBuilder eventBuilder = m_typeBuilder.DefineEvent(
eventInfo.Name,
eventInfo.Attributes,
eventInfo.EventHandlerType);
MethodInfo addMethod = eventInfo.GetAddMethod();
if (addMethod != null) {
MethodBuilder addMethodBuilder = m_interfaceMethodDict[addMethod];
eventBuilder.SetAddOnMethod(addMethodBuilder);
}
MethodInfo removeMethod = eventInfo.GetRemoveMethod();
if (removeMethod != null) {
MethodBuilder removeMethodBuilder = m_interfaceMethodDict[removeMethod];
eventBuilder.SetRemoveOnMethod(removeMethodBuilder);
}
MethodInfo raiseMethod = eventInfo.GetRaiseMethod();
if (raiseMethod != null) {
MethodBuilder raiseMethodBuilder = m_interfaceMethodDict[raiseMethod];
eventBuilder.SetRaiseMethod(raiseMethodBuilder);
}
}
示例8: GetBaseEventDefinition
static EventInfo GetBaseEventDefinition (EventInfo evt)
{
MethodInfo method = evt.GetAddMethod (true);
if (method == null || !method.IsVirtual)
method = evt.GetRaiseMethod (true);
if (method == null || !method.IsVirtual)
method = evt.GetRemoveMethod (true);
if (method == null || !method.IsVirtual)
return null;
MethodInfo baseMethod = method.GetBaseMethod ();
if (baseMethod != null && baseMethod != method) {
BindingFlags flags = method.IsPublic ? BindingFlags.Public : BindingFlags.NonPublic;
flags |= method.IsStatic ? BindingFlags.Static : BindingFlags.Instance;
return baseMethod.DeclaringType.GetEvent (evt.Name, flags);
}
return null;
}