Delegate property and component serialization

  • Thread starter Thread starter Arthur Dent
  • Start date Start date
A

Arthur Dent

Hello all...

I have a component which i wrote, which is used for automatically emailing
errors, so that when an app (usually a website) goes into production, i
automatically get emailed about any exceptions which occur on the site. A
friend wanted to use the same thing but have the ability to override the
OnError action, because their mail handler had to be handled in an unusual
manner.

To accomodate his need, i added a delegate definition to the component. Now
it allows the user to either accept the intrinsic behaviour or replace it
with their own... for an odd email handler, or logging or simply
messageboxing the user.

The only problem is now i cannot drag the component onto a form designer
anymore, because it says the Handler property is not serializable.
Is there any way that i can get around that? Isnt a delegate basically a
function pointer? which is basically an Int? which should be serializable?

My code (partial/relevant) is as follows:
===== BEGIN CODE ==============================================
Public Class ErrorHandler
Inherits System.ComponentModel.Component

Delegate Sub ExceptionHandler(ByVal ex As Exception, ByVal OneTimeExtra
As String)
Private pHandler As ExceptionHandler = AddressOf PrivateHandler

Public Property Handler() As ExceptionHandler
Get
Return pHandler
End Get
Set(ByVal Value As ExceptionHandler)
If Value Is Nothing Then _
pHandler = AddressOf PrivateHandler _
Else _
pHandler = Value
End Set
End Property

Private Sub PrivateHandler(ByVal ex As Exception, ByVal OneTimeExtra As
String)
..... <intrinsic handling>
End Sub
End Class
===== END CODE ================================================

Thanks in advance,
- Arthur Dent.
 
You should use events instead of delegates directly for this so the problem
should go away.
If not, you can mark the delegate property with the
<DesignerSerialisationVisibility(DesignerSerialisationVisibility.Hidden)>
attribute.
 
The only thing which i would see as a problem with using events is that
i want the custom handler to completely supplant the built-in handler
(if a custom one is specified). If i used events, and the consumer handled
the event, then it would happen *in addition to* the built in handler as
opposed
to *instead of*, no?

Thanks for the response. The DesignerSerialisationVisibility, will that have
any effects
on the component as far as it "forgetting" who the current handler-routine
is?

Thanks again.
 
The DesignerSerialisationVisibility attribute will have only affect in
designmode that, is when you open the component in designmode the property
cannot be modified from designmode.
 
Thanks for the help, worked beautifully.

cody said:
The DesignerSerialisationVisibility attribute will have only affect in
designmode that, is when you open the component in designmode the property
cannot be modified from designmode.
 
Back
Top