本文整理汇总了C#中System.Reflection.EventInfo.GetRemoveMethod方法的典型用法代码示例。如果您正苦于以下问题:C# EventInfo.GetRemoveMethod方法的具体用法?C# EventInfo.GetRemoveMethod怎么用?C# EventInfo.GetRemoveMethod使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.EventInfo
的用法示例。
在下文中一共展示了EventInfo.GetRemoveMethod方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RemoveEventDecoratorWeaver
public RemoveEventDecoratorWeaver(IEventTypeBuilder eventTypeBuilder, EventInfo @event, IWeavingSettings weavingSettings)
: base(@event.GetRemoveMethod(), weavingSettings)
{
MethodEndWeaver = new MethodEndWeaver();
MethodScopeWeaver = new RemoveEventDecoratorScopeWeaver(method, weavingSettings);
MethodDefintionWeaver = new RemoveEventMethodSignatureWeaver(eventTypeBuilder, weavingSettings.TypeDefinition);
}
示例2: EventMemberDescriptor
/// <summary>
/// Initializes a new instance of the <see cref="EventMemberDescriptor" /> class.
/// </summary>
/// <param name="ei">The ei.</param>
/// <param name="accessMode">The access mode.</param>
public EventMemberDescriptor(EventInfo ei, InteropAccessMode accessMode = InteropAccessMode.Default)
{
CheckEventIsCompatible(ei, true);
EventInfo = ei;
m_Add = ei.GetAddMethod(true);
m_Remove = ei.GetRemoveMethod(true);
IsStatic = m_Add.IsStatic;
}
示例3: ReflectionEventDescriptor
public ReflectionEventDescriptor (EventInfo eventInfo) : base (eventInfo.Name, (Attribute[]) eventInfo.GetCustomAttributes (true))
{
_eventInfo = eventInfo;
_componentType = eventInfo.DeclaringType;
_eventType = eventInfo.EventHandlerType;
add_method = eventInfo.GetAddMethod ();
remove_method = eventInfo.GetRemoveMethod ();
}
示例4: TryCreateIfVisible
/// <summary>
/// Tries to create a new StandardUserDataEventDescriptor, returning <c>null</c> in case the method is not
/// visible to script code.
/// </summary>
/// <param name="ei">The EventInfo.</param>
/// <param name="accessMode">The <see cref="InteropAccessMode" /></param>
/// <returns>A new StandardUserDataEventDescriptor or null.</returns>
public static EventMemberDescriptor TryCreateIfVisible(EventInfo ei, InteropAccessMode accessMode)
{
if (!CheckEventIsCompatible(ei, false))
return null;
if (ei.GetVisibilityFromAttributes() ?? (ei.GetAddMethod().IsPublic && ei.GetRemoveMethod().IsPublic))
return new EventMemberDescriptor(ei, accessMode);
return null;
}
示例5: BuildRemover
private void BuildRemover(TypeBuilder typeBuilder, EventInfo contractProperty, EventBuilder builder)
{
var removeMethod = contractProperty.GetRemoveMethod();
if (null != removeMethod)
{
var removeMethodBuilder = new ProxyMethodImplementationStrategy().BuildMethodProxy(typeBuilder, removeMethod);
builder.SetRemoveOnMethod(removeMethodBuilder);
}
}
示例6: CheckEventIsCompatible
/// <summary>
/// Checks if the event is compatible with a standard descriptor
/// </summary>
/// <param name="ei">The EventInfo.</param>
/// <param name="throwException">if set to <c>true</c> an exception with the proper error message is thrown if not compatible.</param>
/// <returns></returns>
/// <exception cref="System.ArgumentException">
/// Thrown if throwException is <c>true</c> and one of this applies:
/// The event is declared in a value type
/// or
/// The event does not have both add and remove methods
/// or
/// The event handler type doesn't implement a public Invoke method
/// or
/// The event handler has a return type which is not System.Void
/// or
/// The event handler has more than MAX_ARGS_IN_DELEGATE parameters
/// or
/// The event handler has a value type parameter or a by ref parameter
/// or
/// The event handler signature is not a valid method according to <see cref="MethodMemberDescriptor.CheckMethodIsCompatible"/>
/// </exception>
public static bool CheckEventIsCompatible(EventInfo ei, bool throwException)
{
if (ei.DeclaringType.IsValueType)
{
if (throwException) throw new ArgumentException("Events are not supported on value types");
return false;
}
if ((ei.GetAddMethod(true) == null) || (ei.GetRemoveMethod(true) == null))
{
if (throwException) throw new ArgumentException("Event must have add and remove methods");
return false;
}
MethodInfo invoke = ei.EventHandlerType.GetMethod("Invoke");
if (invoke == null)
{
if (throwException) throw new ArgumentException("Event handler type doesn't seem to be a delegate");
return false;
}
if (!MethodMemberDescriptor.CheckMethodIsCompatible(invoke, throwException))
return false;
if (invoke.ReturnType != typeof(void))
{
if (throwException) throw new ArgumentException("Event handler cannot have a return type");
return false;
}
ParameterInfo[] pars = invoke.GetParameters();
if (pars.Length > MAX_ARGS_IN_DELEGATE)
{
if (throwException) throw new ArgumentException(string.Format("Event handler cannot have more than {0} parameters", MAX_ARGS_IN_DELEGATE));
return false;
}
foreach (ParameterInfo pi in pars)
{
if (pi.ParameterType.IsValueType)
{
if (throwException) throw new ArgumentException("Event handler cannot have value type parameters");
return false;
}
else if (pi.ParameterType.IsByRef)
{
if (throwException) throw new ArgumentException("Event handler cannot have by-ref type parameters");
return false;
}
}
return true;
}
示例7: ImplementEvent
/// <summary>
/// Implements the event.
/// </summary>
/// <param name="eventToImplement">The event to implement.</param>
/// <param name="targetInterface">The target interface.</param>
/// <returns></returns>
protected override EventBuilder ImplementEvent(EventInfo eventToImplement, Type targetInterface)
{
EventBuilder eventBuilder = this.TypeBuilder.DefineEvent(eventToImplement.Name, EventAttributes.None, eventToImplement.EventHandlerType);
MethodInfo addMethodInfo = eventToImplement.GetAddMethod();
MethodInfo removeMethodInfo = eventToImplement.GetRemoveMethod();
MethodBuilder addMethodBuilder = this.ImplementMethod(addMethodInfo, targetInterface);
MethodBuilder removeMethodBuilder = this.ImplementMethod(removeMethodInfo, targetInterface);
eventBuilder.SetAddOnMethod(addMethodBuilder);
eventBuilder.SetRemoveOnMethod(removeMethodBuilder);
return eventBuilder;
}
示例8: ImplementEvent
private EventBuilder ImplementEvent(TypeBuilder typeBuilder, EventInfo eventToImplement, Type targetInterface)
{
var eventBuilder = typeBuilder.DefineEvent(eventToImplement.Name, EventAttributes.None, eventToImplement.EventHandlerType);
var addMethodInfo = eventToImplement.GetAddMethod();
var removeMethodInfo = eventToImplement.GetRemoveMethod();
var addMethodBuilder = ImplementMethod(typeBuilder, addMethodInfo, targetInterface);
var removeMethodBuilder = ImplementMethod(typeBuilder, removeMethodInfo, targetInterface);
eventBuilder.SetAddOnMethod(addMethodBuilder);
eventBuilder.SetRemoveOnMethod(removeMethodBuilder);
return eventBuilder;
}
示例9: TryCreateIfVisible
/// <summary>
/// Tries to create a new StandardUserDataEventDescriptor, returning <c>null</c> in case the method is not
/// visible to script code.
/// </summary>
/// <param name="ei">The EventInfo.</param>
/// <param name="accessMode">The <see cref="InteropAccessMode" /></param>
/// <returns>A new StandardUserDataEventDescriptor or null.</returns>
public static EventMemberDescriptor TryCreateIfVisible(EventInfo ei, InteropAccessMode accessMode)
{
if (!CheckEventIsCompatible(ei, false))
return null;
MethodInfo addm = ei.GetAddMethod();
MethodInfo remm = ei.GetRemoveMethod();
if (ei.GetVisibilityFromAttributes() ?? ((remm != null && remm.IsPublic) && (addm != null && addm.IsPublic)))
return new EventMemberDescriptor(ei, accessMode);
return null;
}
示例10: ReflectionEvent
public ReflectionEvent(EventInfo eventInfo, IClass declaringType) : base(declaringType, eventInfo.Name)
{
this.ReturnType = ReflectionReturnType.Create(this, eventInfo.EventHandlerType, attributeProvider: eventInfo);
// get modifiers
MethodInfo methodBase = null;
try {
methodBase = eventInfo.GetAddMethod(true);
} catch (Exception) {}
if (methodBase == null) {
try {
methodBase = eventInfo.GetRemoveMethod(true);
} catch (Exception) {}
}
ModifierEnum modifiers = ModifierEnum.None;
if (methodBase != null) {
if (methodBase.IsStatic) {
modifiers |= ModifierEnum.Static;
}
if (methodBase.IsAssembly) {
modifiers |= ModifierEnum.Internal;
}
if (methodBase.IsPrivate) { // I assume that private is used most and public last (at least should be)
modifiers |= ModifierEnum.Private;
} else if (methodBase.IsFamily || methodBase.IsFamilyOrAssembly) {
modifiers |= ModifierEnum.Protected;
} else if (methodBase.IsPublic) {
modifiers |= ModifierEnum.Public;
} else {
modifiers |= ModifierEnum.Internal;
}
if (methodBase.IsFinal) {
modifiers |= ModifierEnum.Sealed;
} else if (methodBase.IsAbstract) {
modifiers |= ModifierEnum.Abstract;
} else if (methodBase.IsVirtual) {
modifiers |= ModifierEnum.Virtual;
}
} else {
// assume public property, if no methodBase could be get.
modifiers = ModifierEnum.Public;
}
this.Modifiers = modifiers;
}
示例11: ReflectionEvent
public ReflectionEvent(EventInfo eventInfo, XmlDocument docs)
{
FullyQualifiedName = String.Concat(eventInfo.DeclaringType.FullName, ".", eventInfo.Name);
if (docs != null) {
XmlNode node = docs.SelectSingleNode ("/Type/Members/Member[@MemberName='" + eventInfo.Name + "']/Docs/summary");
if (node != null) {
Documentation = node.InnerXml;
}
}
// get modifiers
MethodInfo methodBase = null;
try {
methodBase = eventInfo.GetAddMethod(true);
} catch (Exception) {}
if (methodBase == null) {
try {
methodBase = eventInfo.GetRemoveMethod(true);
} catch (Exception) {}
}
if (methodBase != null) {
if (methodBase.IsStatic) {
modifiers |= ModifierEnum.Static;
}
if (methodBase.IsAssembly) {
modifiers |= ModifierEnum.Internal;
}
if (methodBase.IsPrivate) { // I assume that private is used most and public last (at least should be)
modifiers |= ModifierEnum.Private;
} else if (methodBase.IsFamily) {
modifiers |= ModifierEnum.Protected;
} else if (methodBase.IsPublic) {
modifiers |= ModifierEnum.Public;
} else if (methodBase.IsFamilyOrAssembly) {
modifiers |= ModifierEnum.ProtectedOrInternal;
} else if (methodBase.IsFamilyAndAssembly) {
modifiers |= ModifierEnum.Protected;
modifiers |= ModifierEnum.Internal;
}
} else { // assume public property, if no methodBase could be get.
modifiers = ModifierEnum.Public;
}
returnType = new ReflectionReturnType(eventInfo.EventHandlerType );
}
示例12: 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);
}
示例13: GuardRemoveMethodExists
private static void GuardRemoveMethodExists(EventInfo targetEvent)
{
if (targetEvent.GetRemoveMethod() == null)
{
throw new ArgumentException(string.Format("The event '{0}' does not have a public Remove method",
targetEvent.Name));
}
}
示例14: DynamicEvent
public DynamicEvent(EventInfo eventInfo, object instance)
{
_addMethod = new DynamicMethod(eventInfo.GetAddMethod(true), instance);
_removeMethod = new DynamicMethod(eventInfo.GetRemoveMethod(true), instance);
}
示例15: ShouldReserveName
private static bool ShouldReserveName(EventInfo member)
{
bool hasNonPrivate = false;
MethodInfo miAdd = member.GetAddMethod();
if (miAdd != null)
{
hasNonPrivate |= ShouldReserveName(miAdd, false);
}
MethodInfo miRemove = member.GetRemoveMethod();
if (miRemove != null)
{
hasNonPrivate |= ShouldReserveName(miRemove, false);
}
return hasNonPrivate;
}