I'm trying to serialize a class using the binary formatter without serializing the
'static pastFirstCall as Boolean' variable. Normally private (module-scope)
variables are serialized unless the <NonSerialize d> attribute is used.
Public Function NextMessageNo() As Integer
<NonSerialized( )> Static pastFirstCall As Boolean = False 'This is
being Serialized!!!!! !!!!!
If Not pastFirstCall Then
mNextMessageNum ber = mNextPersistabl eMessageNo
pastFirstCall = True
End If
NextMessageNo = mNextMessageNum ber + 1
mNextMessageNum ber = NextMessageNo
End Function
<NonSerialized( )> Private mNextMessageNum ber As Integer
Using Reflector, I can see that, internally, pastFirstCall is declared as a private
variable as:
Private $STATIC$NextMes sageNo$2008$pas tFirstCall As BooleanThe problem is that the
<NonSerialize d> attribute is not carried forward to this declaration. Are there any
workarounds other than changing the delcaration to private. Has anyone written a
custom attribute to fix it? I have a ton of static's (which I like because they
limit the scope, thus reducing the complexity) and don't want to go thru all my code
changing them to private module-scope declarations. Almost forgot, I'm using the
..NET Framework 1.0 with the latest service packs. Any Ideas?
Thanks - JackRazz