GetAddMethod() public method

public GetAddMethod ( ) : MethodInfo
return MethodInfo
Esempio n. 1
0
 public AddEventDecoratorWeaver(IEventTypeBuilder eventTypeBuilder, EventInfo @event, IWeavingSettings weavingSettings)
     : base(@event.GetAddMethod(), weavingSettings)
 {
     MethodEndWeaver = new MethodEndWeaver();
     MethodScopeWeaver = new AddEventDecoratorScopeWeaver(method, weavingSettings);
     MethodDefintionWeaver = new AddEventMethodSignatureWeaver(eventTypeBuilder, weavingSettings.TypeDefinition);
 }
 /// <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;
 }
Esempio n. 3
0
        public static bool IsMatchedTo(this EventInfo firstEvent, EventInfo secondEvent)
        {
            if (firstEvent.IsNull() || !firstEvent.Name.Equals(secondEvent.Name) || firstEvent.EventHandlerType != secondEvent.EventHandlerType) {
                return false;
            }

            return firstEvent.GetAddMethod().IsMatchedTo(secondEvent.GetAddMethod());
        }
Esempio n. 4
0
		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 ();
		}
		/// <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;
		}
        private void BuildAdder(TypeBuilder typeBuilder, EventInfo contractProperty, EventBuilder builder)
        {
            var addMethod = contractProperty.GetAddMethod();

            if (null != addMethod)
            {
                var addMethodBuilder = new ProxyMethodImplementationStrategy().BuildMethodProxy(typeBuilder, addMethod);
                builder.SetAddOnMethod(addMethodBuilder);
            }
        }
		/// <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;
		}
Esempio n. 8
0
 /// <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;
 }
 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;
 }
        public MvxEventHandlerEventInfoTargetBinding(object target, EventInfo targetEventInfo)
            : base(target)
        {
            _targetEventInfo = targetEventInfo;

            // 	addMethod is used because of error:
            // "Attempting to JIT compile method '(wrapper delegate-invoke) <Module>:invoke_void__this___UIControl_EventHandler (MonoTouch.UIKit.UIControl,System.EventHandler)' while running with --aot-only."
            // see https://bugzilla.xamarin.com/show_bug.cgi?id=3682

            var addMethod = _targetEventInfo.GetAddMethod();
            addMethod.Invoke(target, new object[] {new EventHandler(HandleEvent)});
        }
Esempio n. 11
0
            Event LoadEvent(System.Reflection.EventInfo refEvent)
            {
                Event eventObject = new Event
                {
                    Name             = refEvent.Name,
                    IsStatic         = refEvent.GetAddMethod().IsStatic,
                    EventHandlerType = GetTypeFullName(refEvent.EventHandlerType),
                    Attributes       = refEvent.Attributes,
                };

                return(eventObject);
            }
Esempio n. 12
0
		/// <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;
		}
        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 );
        }
Esempio n. 14
0
		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;
			
		}
 public MBeanInternalNotificationInfo(EventInfo eventInfo, IMBeanInfoFactory factory)
 {
     _handlerType = eventInfo.GetAddMethod().GetParameters()[0].ParameterType;
      _handlerGenericArgument = _handlerType.GetGenericArguments()[0];
      if (_handlerType.GetGenericTypeDefinition() == typeof(EventHandler<>) &&
      (typeof(Notification).IsAssignableFrom(_handlerGenericArgument)
       || typeof(NotificationEventArgs).IsAssignableFrom(_handlerGenericArgument)))
      {
     _notifInfo = factory.CreateMBeanNotificationInfo(eventInfo, _handlerType);
      }
      else
      {
     throw new NotCompliantMBeanException(eventInfo.DeclaringType.AssemblyQualifiedName);
      }
      _eventInfo = eventInfo;
 }
Esempio n. 16
0
        /// <summary>
        /// Hack for compatibility RabbitMQ.Client library between 3.4.x and 3.5.x versions
        /// ConnectionShutdownEventHandler replaced by Eventhandler<ShutdownEventArgs> - https://github.com/rabbitmq/rabbitmq-dotnet-client/commit/84ca5552a338a86c9af124331adca230accf3be3
        /// using reflection for understand, what type of delegate we must use for IConnection.ConnectionShutdown:
        /// - EventHandler<ShutdownEventArgs> for 3.5.x version
        /// - ConnectionShutdownEventHandler for 3.4.x and early version
        /// </summary>
        private void PrepareConnectionShutdownEventHandler()
        {
            System.Reflection.EventInfo connectionShutdownEventInfo = typeof(IConnection).GetEvent("ConnectionShutdown");
            _connectionShutdownEventAddMethod = connectionShutdownEventInfo.GetAddMethod();

            Type delegateType = connectionShutdownEventInfo.EventHandlerType;

            System.Reflection.MethodInfo shutdownAmqpMethodInfo = null;

            if (delegateType.IsConstructedGenericType && delegateType.GetGenericTypeDefinition() == typeof(EventHandler <>))
            {
                shutdownAmqpMethodInfo = typeof(RabbitMQ).GetMethod("ShutdownAmqp35", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
            }
            else
            {
                shutdownAmqpMethodInfo = typeof(RabbitMQ).GetMethod("ShutdownAmqp", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
            }

            _connectionShutdownEventHandler = shutdownAmqpMethodInfo.CreateDelegate(delegateType, this);
        }
Esempio n. 17
0
        /// <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);
        }
Esempio n. 18
0
		public EventDetail(RootDetail parent, EventInfo ei)
			: base(parent, ei)
		{
			_name = ei.Name;
			_visibility = VisibilityUtil.GetVisibilityFor(ei.GetAddMethod(true));
			_category = "event";

			CodeStringBuilder csb = new CodeStringBuilder();

			AppendAttributesDeclaration(csb);

			csb.Mode = AppendMode.Html;
			csb.AppendVisibility(_visibility);
			csb.AppendText(" ");
			csb.Mode = AppendMode.Both;

			csb.AppendKeyword("event ");
			csb.AppendType(ei.EventHandlerType);
			csb.AppendText(" ");
			csb.AppendText(ei.Name);

			_declaration = csb.ToString();
			_declarationHtml = csb.ToHtmlString();
		}
Esempio n. 19
0
 private static void GuardAddMethodExists(EventInfo targetEvent)
 {
     if(targetEvent.GetAddMethod() == null)
     {
         throw new ArgumentException(string.Format("The event '{0}' does not have a public Add method",
                                                   targetEvent.Name));
     }
 }
Esempio n. 20
0
        private static EventInfo GetParentDefinition(EventInfo ev)
        {
            Contract.Requires(ev != null);

            // note that this only works for RuntimeMethodInfo
            MethodInfo add = ev.GetAddMethod(true);

            RuntimeMethodInfo rtAdd = add as RuntimeMethodInfo;

            if (rtAdd != null)
            {
                rtAdd = rtAdd.GetParentDefinition();
                if (rtAdd != null) 
                    return rtAdd.DeclaringType.GetEvent(ev.Name);
            }
            return null;
        }
Esempio n. 21
0
        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;
        }
Esempio n. 22
0
        /// <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);
            }
        }
Esempio n. 23
0
		/// <summary>Writes XML documenting an event.</summary>
		/// <param name="writer">XmlWriter to write on.</param>
		/// <param name="eventInfo">Event to document.</param>
		private void WriteEvent(XmlWriter writer, EventInfo eventInfo)
		{
			string memberName = MemberID.GetMemberID(eventInfo);

			string name = eventInfo.Name;
			string interfaceName = null;

			int lastIndexOfDot = name.LastIndexOf('.');
			if (lastIndexOfDot != -1)
			{
				//this is an explicit interface implementation. if we don't want
				//to document them, get out of here quick...
				if (!this.rep.DocumentExplicitInterfaceImplementations) return;

				interfaceName = name.Substring(0, lastIndexOfDot);
				lastIndexOfDot = interfaceName.LastIndexOf('.');
				if (lastIndexOfDot != -1)
					name = name.Substring(lastIndexOfDot + 1);

				//check if we want to document this interface.
				ImplementsInfo implements = null;
				MethodInfo adder = eventInfo.GetAddMethod(true);
				if (adder != null)
				{
					implements = implementations[adder.ToString()];
				}
				if (implements == null)
				{
					MethodInfo remover = eventInfo.GetRemoveMethod(true);
					if (remover != null)
					{
						implements = implementations[remover.ToString()];
					}
				}
				if (implements != null) return;
			}

			writer.WriteStartElement("event");
			writer.WriteAttributeString("name", name);
			writer.WriteAttributeString("id", memberName);
			writer.WriteAttributeString("access", GetMethodAccessValue(eventInfo.GetAddMethod(true)));
			writer.WriteAttributeString("contract", GetMethodContractValue(eventInfo.GetAddMethod(true)));
			Type t = eventInfo.EventHandlerType;
			writer.WriteAttributeString("type", MemberID.GetTypeName(t));
			writer.WriteAttributeString("valueType", t.IsValueType.ToString().ToLower());

			bool inherited = eventInfo.DeclaringType != eventInfo.ReflectedType;

			if (inherited)
			{
				writer.WriteAttributeString("declaringType", MemberID.GetDeclaringTypeName(eventInfo));
			}

			if (interfaceName != null)
			{
				writer.WriteAttributeString("interface", interfaceName);
			}

			if (eventInfo.IsMulticast)
			{
				writer.WriteAttributeString("multicast", "true");
			}

			if (inherited)
			{
				WriteInheritedDocumentation(writer, memberName, eventInfo.DeclaringType);
			}
			else
			{
				WriteEventDocumentation(writer, memberName, true);
			}
			WriteCustomAttributes(writer, eventInfo);

			if (implementations != null)
			{
				ImplementsInfo implements = null;
				MethodInfo adder = eventInfo.GetAddMethod(true);
				if (adder != null)
				{
					implements = implementations[adder.ToString()];
				}
				if (implements == null)
				{
					MethodInfo remover = eventInfo.GetRemoveMethod(true);
					if (remover != null)
					{
						implements = implementations[remover.ToString()];
					}
				}
				if (implements != null)
				{
					writer.WriteStartElement("implements");
					MemberInfo InterfaceMethod = (MemberInfo)implements.InterfaceMethod;
					EventInfo InterfaceEvent = 
						InterfaceMethod.DeclaringType.GetEvent(InterfaceMethod.Name.Substring(4));
					writer.WriteAttributeString("name", InterfaceEvent.Name);
					writer.WriteAttributeString("id", MemberID.GetMemberID(InterfaceEvent));
					writer.WriteAttributeString("interface", implements.InterfaceType.Name);
					writer.WriteAttributeString("interfaceId", MemberID.GetMemberID(implements.InterfaceType));
					writer.WriteAttributeString("declaringType", implements.InterfaceType.FullName.Replace('+', '.'));
					writer.WriteEndElement();
				}
			}

			writer.WriteEndElement();
		}
Esempio n. 24
0
 private Delegate attachEventHandler(EventInfo @event, string methodName, object realButton)
 {
     MethodInfo method = GetType().GetMethod(methodName, BindingFlags.NonPublic | BindingFlags.Instance);
     Delegate d = Delegate.CreateDelegate(@event.EventHandlerType, this, method);
     @event.GetAddMethod().Invoke(realButton, new object[] { d });
     return d;
 }
Esempio n. 25
0
        private void AddEvent(EventInfo @event, IProxyGenerationHook hook)
        {
            var addMethod = @event.GetAddMethod(true);
            var removeMethod = @event.GetRemoveMethod(true);
            MetaMethod adder = null;
            MetaMethod remover = null;

            if (addMethod != null)
            {
                adder = AddMethod(addMethod, hook, false);
            }

            if (removeMethod != null)
            {
                remover = AddMethod(removeMethod, hook, false);
            }

            if (adder == null && remover == null)
            {
                return;
            }

            events[@event] = new MetaEvent(@event.Name,
                                           @event.DeclaringType, @event.EventHandlerType, adder, remover, EventAttributes.None);
        }
Esempio n. 26
0
 public CompiledEventScope(SymInfo si, EventInfo ei, CompiledScope declaringType)
 {
     this.si = si;
     this.ei = ei;
     string[] args = declaringType.TemplateArguments;
     if (args != null)
     {
         generic_args = new List<string>();
         generic_args.AddRange(args);
     }
     if (generic_args != null)
     {
         //TypeScope ts = declaringType.instances[ei.EventHandlerType.GenericParameterPosition];
         this.sc = CompiledScope.get_type_instance(ei.EventHandlerType, declaringType.instances);
     }
     else
         this.sc = TypeTable.get_compiled_type(ei.EventHandlerType);
     if (si.name == null)
         AssemblyDocCache.AddDescribeToComplete(this.si, ei);
     this.si.name = ei.Name;
     this.si.description = this.ToString();
     this.topScope = declaringType;
     MethodInfo acc_mi = ei.GetAddMethod(true);
     is_static = acc_mi.IsStatic;
     if (acc_mi.IsPrivate)
     {
         this.acc_mod = access_modifer.private_modifer;
         this.si.acc_mod = access_modifer.private_modifer;
     }
     else if (acc_mi.IsFamily || acc_mi.IsFamilyOrAssembly)
     {
         this.acc_mod = access_modifer.protected_modifer;
         this.si.acc_mod = access_modifer.protected_modifer;
     }
     else if (acc_mi.IsFamilyAndAssembly || acc_mi.IsAssembly)
     {
         this.acc_mod = access_modifer.internal_modifer;
         this.si.acc_mod = access_modifer.internal_modifer;
     }
     //this.si.describe += "\n"+AssemblyDocCache.GetDocumentation(ei.DeclaringType.Assembly,"E:"+ei.DeclaringType.FullName+"."+ei.Name);
 }
Esempio n. 27
0
        static private void AppendEventInfo(StringBuilder builder, Type type, EventInfo info)
        {
            int propertyStart = builder.Length;

            AppendParameterType(builder, info.EventHandlerType);
            builder.Append(" ");
            builder.Append(info.Name);

            builder.Append(" {");
            bool gettable = AppendPropertyMethod(builder, type, info.GetAddMethod(), "add");
            bool settable = AppendPropertyMethod(builder, type, info.GetRemoveMethod(), "remove");
            if (gettable || settable)
            {
                builder.Append(" }");
                builder.Append(Environment.NewLine);
            }
            else
            {
                builder.Length = propertyStart;
            }
        }
Esempio n. 28
0
 public override System.Reflection.MethodInfo GetAddMethod(bool nonPublic)
 {
     return(_innerEventInfo.GetAddMethod(nonPublic));
 }
Esempio n. 29
0
	void OutlineEvent (EventInfo ei)
	{
		MethodBase accessor = ei.GetAddMethod (true);
		
		o.Write (GetMethodVisibility (accessor));
		o.Write ("event ");
		o.Write (FormatType (ei.EventHandlerType));
		o.Write (" ");
		o.Write (ei.Name);
		o.Write (";");
	}
Esempio n. 30
0
        protected EventInfo[] GetEvents_impl(BindingFlags bf, Type reftype)
        {
            ArrayList        l = new ArrayList();
            bool             match;
            MethodAttributes mattrs;
            MethodInfo       accessor;

            initialize();

            EventInfo[] events = GetEvents_internal(reftype);

            for (int i = 0; i < events.Length; i++)
            {
                EventInfo c = events [i];

                match    = false;
                accessor = c.GetAddMethod(true);
                if (accessor == null)
                {
                    accessor = c.GetRemoveMethod(true);
                }
                if (accessor == null)
                {
                    continue;
                }
                mattrs = accessor.Attributes;
                if ((mattrs & MethodAttributes.MemberAccessMask) == MethodAttributes.Public)
                {
                    if ((bf & BindingFlags.Public) != 0)
                    {
                        match = true;
                    }
                }
                else
                {
                    if ((bf & BindingFlags.NonPublic) != 0)
                    {
                        match = true;
                    }
                }
                if (!match)
                {
                    continue;
                }
                match = false;
                if ((mattrs & MethodAttributes.Static) != 0)
                {
                    if ((bf & BindingFlags.Static) != 0)
                    {
                        match = true;
                    }
                }
                else
                {
                    if ((bf & BindingFlags.Instance) != 0)
                    {
                        match = true;
                    }
                }
                if (!match)
                {
                    continue;
                }
                l.Add(c);
            }
            EventInfo[] result = new EventInfo [l.Count];
            l.CopyTo(result);
            return(result);
        }
		public static int GetIcon(EventInfo eventinfo)
		{
			if (eventinfo.GetAddMethod(true) != null) {
				return EventIndex + GetIcon(eventinfo.GetAddMethod(true)) - MethodIndex;
			}
			return EventIndex;
		}
 public static Type GetEventHandlerType(EventInfo eventInfo)
 {
     if (eventInfo == null)
     {
         throw new ArgumentNullException("eventInfo");
     }
     MethodInfo addMethod = eventInfo.GetAddMethod(true);
     if (addMethod != null)
     {
         ParameterInfo[] parameters = addMethod.GetParameters();
         Type superClass = typeof(Delegate);
         for (int i = 0; i < parameters.Length; i++)
         {
             Type parameterType = parameters[i].ParameterType;
             if (IsSubclassOf(parameterType, superClass))
             {
                 return parameterType;
             }
         }
     }
     return null;
 }
Esempio n. 33
0
 // Utility method for use with the AddButton<event>Handler API methods.
 protected void AddButtonEventHandler(EventInfo Event, Action<object> Handler)
 {
     Delegate d = Delegate.CreateDelegate(Event.EventHandlerType, Handler.Target, Handler.Method);
     MethodInfo addHandler = Event.GetAddMethod();
     addHandler.Invoke(this.Button, new object[] { d });
 }
Esempio n. 34
0
		void WriteEventSignatureCS (EventInfo mi)
		{
			WriteMethodAttributesCS (
				mi.GetAddMethod ().Attributes, false);
			output.WriteString (CSharpName (mi.EventHandlerType));
			output.WriteString (" ");
			output.WriteString (mi.Name);
			output.WriteString (";");
		}