Don't most (all?) events in .NET follow the EventHandler/EventArgs pattern:

 public class StatementEventArgs : EventArgs
 {
  public IMappedStatement MappedStatement;
  public StatementEventType Type;
  public object ParameterObject;
  public object Result;
 }

 public interface IMappedStatementEvents
 {
  event EventHandler<StatementEventArgs> PreInsert;
  event EventHandler<StatementEventArgs> PreSelect;
  event EventHandler<StatementEventArgs> PreUpdateOrDelete;
  event EventHandler<StatementEventArgs> PostInsert;
  event EventHandler<StatementEventArgs> PostSelect;
  event EventHandler<StatementEventArgs> PostUpdateOrDelete;  
 }

 // Castle.MicroKernel.KernelEventSupport
 public class MappedStatementEventSupport : IMappedStatementEvents
 {
  private static readonly object PreInsertEvent = new object();
  // snip

  private EventHandlerList events = new EventHandlerList();

  public event EventHandler<StatementEventArgs> PreInsert
  {
  add { events.AddHandler(PreInsertEvent, value); }
  remove { events.RemoveHandler(PreInsertEvent, value); }
  }

  protected virtual object RaisePreInsert(IMappedStatement mappedStatement, 
object parameterObject)
  {
   EventHandler<StatementEventArgs> handler = 
(EventHandler<StatementEventArgs>) events[PreInsertEvent];
   // TODO: create StatementEventArgs and Invoke each item in 
handler.GetInvocationList()
  }

  // snip
 }

 public class MappedStatement : MappedStatementEventSupport, IMappedStatement
 {
  // add calls to raise events: RaisePreInsert(mappedStatement, 
parameterObject);
 }

Is there a reason why we rolled our own? 

I like this:

 mappedStatement.PreInsert += (s, e) => { 
Console.WriteLine(e.MappedStatement.Id); }

This seems like a lot of code just to register MyConsoleWriter:

 // ???
 PreInsetEventListener[] preInsertEvents = 
  new PreInsetEventListener[mappedStatement.PreInsertListeners.Length + 1];
 mappedStatement.PreInsetEventListener.CopyTo(preInsertEvents, 0);
 preInsertEvents.SetValue(
  new MyConsoleWriter(), 
  mappedStatement.PreInsetEventListener.Length);
 mappedStatement.PreInsetEventListener = preInsertEvents;

Maybe the listeners should be exposed as 
System.Collection.Generic.ICollection<T>:

 mappedStatement.PreInsetEventListener.Add(new MyConsoleWriter());

Also note that I had to write my own class, MyConsoleWriter, instead of just 
the short lambda expression. The standard EventHandler/EventArgs model makes 
the most sense to me.

----- Original Message ----
From: "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED]
Sent: Sunday, June 8, 2008 2:20:46 PM
Subject: svn commit: r664536 [1/4] - in /ibatis/trunk/cs/V3/src: 
Apache.Ibatis.DataMapper.SqlClient.Test.2005/ 
Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/ 
Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/ 
Apache.Ibatis.DataMapper.SqlClie...

Author: gbayon
Date: Sun Jun  8 11:20:44 2008
New Revision: 664536

URL: http://svn.apache.org/viewvc?rev=664536&view=rev
Log:
IBATISNET-271 add event support

Added:
    
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/EventTest.cs
   (with props)
    
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Modules/EventModule.cs
   (with props)
    
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/ScriptBase.cs
   (with props)
    
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Maps/Event.xml
    
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/bin/Debug/SqlMap.event.config
    
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/DataMapperLocalSessionScope.cs  
 (with props)
    ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Model/Events/

[snip]

Reply via email to