[Ironruby-core] events handling

Ivan Porto Carrero ivan at flanders.co.nz
Mon Oct 26 05:12:42 EDT 2009


Hi

I'm trying the following code:

public class ExposingWarrior{
      private readonly int _id;

      public event EventHandler<EventArgs> OnIsExposedChanged;
      public bool IsExposed {get; set; }

      public void Explode(){
          IsExposed = !IsExposed;
          var handler = OnIsExposedChanged;
          if(handler != null){
              handler(this, EventArgs.Empty);
          }
      }

      public bool HasEventSubscriptions{ get { return OnIsExposedChanged !=
null; } }
  }


require File.dirname(__FILE__) + '/spec/bin/ClrModels.dll'

class ClrProxy < ClrModels::ExposingWarrior

  def add_OnIsExposedChanged(handler)
    (@handlers ||= []) << handler
  end

  def remove_OnIsExposedChanged(handler)
    @handlers.delete handler
  end

  def to_s
    "handlers collected: #{(@handlers||[]).size}"
  end
end

pxy = ClrProxy.new
ClrModels::ExposedChangedSubscriber.new(pxy)
puts pxy

######

(master)» ir event_test.rb
handlers collected: 0

---
Met vriendelijke groeten - Best regards - Salutations
Ivan Porto Carrero
GSM: +32.486.787.582
Blog: http://flanders.co.nz
Twitter: http://twitter.com/casualjim
Author of IronRuby in Action (http://manning.com/carrero)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20091026/62f2fa1f/attachment.html>


More information about the Ironruby-core mailing list