tfpt review "/shelveset:VirtualEvents;REDMOND\tomat"

  Enables overriding of events. Given a class like:

  public class C {
      public virtual event Func<int, int> OnEvent;
  }

  you can implement a Ruby subclass D that overrides the event like so:

  class D < C
    def add_OnEvent handler
      puts 'add ' + handler.inspect
      super
    end

    def remove_OnEvent handler
      puts 'remove ' + handler.inspect
      super
    end
  end

  If d.OnEvent += handler is called from C# (or other .NET language) on an 
instance d of class D the Ruby method add_OnEvent gets invoked.

  This shelveset implements the basic building blocks for overriding events. 
One can write helper methods in Ruby to make the code a bit nicer. For example:

  class Module
    def clr_event_add name, &handler
      unmangled = IronRuby::Clr::Name.unmangle(name)
      define_method("add_" + (unmangled.nil? ? name.to_s : unmangled), &handler)
    end
  end

  class D < C
    clr_event_add :on_event do |handler|
      puts 'add' + handler.inspect
      super(handler)
    end
  end

Tomas

Attachment: VirtualEvents.diff
Description: VirtualEvents.diff

_______________________________________________
Ironruby-core mailing list
Ironruby-core@rubyforge.org
http://rubyforge.org/mailman/listinfo/ironruby-core

Reply via email to