locked
How to create delegate with derived type RRS feed

  • Question

  • Hello,

     

    How to make the same with Compact Framework.

    Code Block

     

    Delegate handler = Delegate.CreateDelegate(publishedEvent.EventHandlerType, this, this.GetType().GetMethod("PublicationHandler"));

     

     

     

    It has taken from Composite UI application block

    Code Block

      ///
      /// Initializes a new instance of the class
      ///
      public Publication(EventTopic topic, object publisher, string eventName, WorkItem workItem, PublicationScope scope)
      {
       this.topic = topic;
       this.wrPublisher = new WeakReference(publisher);
       this.scope = scope;
       this.eventName = eventName;
       this.wrWorkItem = new WeakReference(workItem);

       EventInfo publishedEvent =
        publisher.GetType().GetEvent(eventName, BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static);

       if (publishedEvent == null)
       {
        throw new EventBrokerException(String.Format(CultureInfo.CurrentCulture,
         Properties.Resources.CannotFindPublishedEvent, eventName));
       }

       ThrowIfInvalidEventHandler(publishedEvent);
       ThrowIfEventIsStatic(publishedEvent);

       Delegate handler = Delegate.CreateDelegate(publishedEvent.EventHandlerType, this, this.GetType().GetMethod("PublicationHandler"));
       publishedEvent.AddEventHandler(publisher, handler);
      }

     

     

    Monday, October 22, 2007 9:31 AM

Answers

  • You cannot as there's no Delegate.CreatedDelegate() in NETCF (added to NETCF V 3.5 AFAIK).

    If you can get rid of this code or, if not possible, use MethodInfo.Invoke() to invoke the method without delegate.

     

    Monday, October 22, 2007 4:44 PM