delegates

  • Thread starter Thread starter am72de
  • Start date Start date
A

am72de

Hi all,

I have a delegate of type OracleRowUpdatedEventArgs which is inherited
from System.Data.Common.RowUpdatedEventArgs and I have the
OleDbRowUpdatedEventArgs which is inherited from RowUpdatedEventArgs as
well. Saddly I can't create a delegate in this form:

oracleDataAdapter.RowUpdated +=
OracleRowUpdatedEventHandler(da_RowUpdated)

oleDbDataAdapter.RowUpdated +=
OleDbRowUpdatedEventHandler(da_RowUpdated)

private void da_RowUpdated(object sender, RowUpdatedEventArgs e) {}

because their events have different signatures:

private void oracleDataAdapter_RowUpdated (object sender,
OracleRowUpdatedEventArgs e){}

private void oleDbDataAdapter_RowUpdated (object sender,
OleDbRowUpdatedEventArgs e){}

I know it would be very simple to call the "da_RowUpdated"-Method from
oracleDataAdapter_RowUpdated and from oleDbDataAdapter_RowUpdated, but
sadly the event has to be set to an assembly which should be completely
database independent, so I have to look for a solution like the first
case.

Is there a possibility to "downcast" the events to RowUpdatedEventArgs
or does anybody knows a better solution?

Thanks in advance
Andy
 
Would it be possible/viable to provide your own event handler/delegate in
which case you will have complete control ... for example:

public delegate DatabaseRowUpdatedEventHandler(object sender, MyEventArgs e)

public enum MyEventArgsTypes { ORACLE, OLE };
public class MyEventArgs : EventArgs
{
public readonly MyEventArgsTypes DatabaseType;
public MyEventArgs(EventArgs e, MyEventArgsTypes dbType) : base(e)
{
DatabaseType = dbType;
}
}
public class MyClass
{
public event DatabaseRowUpdatedEventHandler DatabaseRowUpdatedEvent;
public MyClass()
{
// other stuff
oracleDataAdapter.RowUpdated += OracleRowUpdatedEventHandler(_oracle);
oleDbDataAdapter.RowUpdated += OleDbRowUpdatedEventHandler(_ole);
}

private void _oracle(object sender, OracleRowUpdatedEventArgs e)
{
try
{
DatabaseRowUpdatedEvent(sender,
new MyEventArgs(e,
MyEventArgsTypes.ORACLE);
}
catch(NullReferenceException) { }
}
private void _ole(object sender, RowUpdatedEventArgs e)
{
try
{
DatabaseRowUpdatedEvent(sender,
new MyEventArgs(e,
MyEventArgsTypes.OLE);
}
catch(NullReferenceException) { }
}
}
 
Hi billr,

unfortunately not. Because of the inner structure of the application, I
can't implement the class MyClass to encapsulate the DataDapters (some
parts are third party products and all the dataAdapters in the code are
generated in one static method which gives a IDbDataAdapter-Interface
back). I can access the original dataadapter only in the moment of
creation, after that I have only a IDbDataAdapter-Interface.

I guess I have to create an array and store the original dataadapters
and the accessory delegates. I assign the _oracle and _ole events like
your example and in _oracle/_ole I search the associated dataadapter in
addiction to the "sender" and so I can call the RowUpdatedEventArgs.
- just a little bit beside your idea :-)
- and sadly a little bit more unkind.

Thanks
Andy
 
Hi,


What you can do is create one method with each signature these method would
convert the different arguments they receive in a common format and then
call a method which does the work. Now alkl you have to do is creating a way
to transform both parameters ( those received in
OracleRowUpdatedEventHandler and OleDbRowUpdatedEventHandler ) in a common
format.



cheers,
 
Hi,

because there are more than one dataadapter and all of them are created
in a single static Method which returns an IDbDataAdapter-Interface the
challenge is exact the transformation - see my answer to billr

Thanks
Andy
 
Back
Top