A few weeks ago I posted an entry about a solution to today's problem with serializing objects that declare events. It was pointed out that there's a better way to handle the list of delegates, and so here's a better version of the code.
_ Private mNonSerializable As EventHandler Private mSerializable As EventHandler
Public Custom Event NameChanged As System.ComponentModel.EventHandler AddHandler(ByVal value As System.ComponentModel.EventHandler) If value.Target.GetType.IsSerializable Then mSerializable = CType([Delegate].Combine(mSerializable, value), EventHandler)
Else mNonSerializable = CType([Delegate].Combine(mNonSerializable, value), EventHandler) End If End AddHandler
RemoveHandler(ByVal value As System.ComponentModel.EventHandler) If value.Target.GetType.IsSerializable Then mSerializable = CType([Delegate].Remove(mSerializable, value), EventHandler)
Else mNonSerializable = CType([Delegate].Remove(mNonSerializable, value), EventHandler) End If End RemoveHandler
RaiseEvent(ByVal sender As Object, ByVal e As System.ComponentModel.EventArgs) If mNonSerializable IsNot Nothing Then mNonSerializable(sender, e) If mSerializable IsNot Nothing Then mSerializable(sender, e) End RaiseEvent End Event
Powered by: newtelligence dasBlog 2.0.7226.0
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.
© Copyright 2012, Marimer LLC
E-mail