Events handling

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 C.
GSM: +32.486.787.582
Blog: http://flanders.co.nz
Twitter: http://twitter.com/casualjim
Author of IronRuby in Action (http://manning.com/carrero)