have it by my bed and I'm reading it 2 pages at a time. Should be into
addressing him as Mr. Lavie from now on :D
On Nov 17, 7:30 pm, Oren Ellenbogen <
oren.ellenbo...@gmail.com> wrote:
> This is the right pattern (I remember Juval wrote an helper class to do it
> in a generic manner)
>
> Another thing you can do is to set the "add" of the event and wrap it
> internally with anonymous method to protect the call.
> Well, this is a stupid idea but fun to think about, so I'll let you figure
> out why (it is stupid).
> Here it is (wrote it in gmail, no compiler):
>
> private event OnDataReceived _dataRecievedEvent = () => {}; // prevent the
> tedious/dangerous if (_dataRecievedEvent != null)
> public event OnDataReceived OnDataReceived
> {
> add {
> _dataRecievedEvent += ()=> { try { value(); } catch(Exception e) {
> _logger.Error(e); } }; // wrap original caller with my protected code.
> }
> remove {
> _dataRecievedEvent -= value; // hmmm... would it work... ?
> }
>
> }
>
> cheers,
> Oren.
>