J
JackRazz
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 <NonSerialized> attribute is used.
Public Function NextMessageNo() As Integer
<NonSerialized()> Static pastFirstCall As Boolean = False 'This is
being Serialized!!!!!!!!!!
If Not pastFirstCall Then
mNextMessageNumber = mNextPersistableMessageNo
pastFirstCall = True
End If
NextMessageNo = mNextMessageNumber + 1
mNextMessageNumber = NextMessageNo
End Function
<NonSerialized()> Private mNextMessageNumber As Integer
Using Reflector, I can see that, internally, pastFirstCall is declared as a private
variable as:
Private $STATIC$NextMessageNo$2008$pastFirstCall As BooleanThe problem is that the
<NonSerialized> 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
'static pastFirstCall as Boolean' variable. Normally private (module-scope)
variables are serialized unless the <NonSerialized> attribute is used.
Public Function NextMessageNo() As Integer
<NonSerialized()> Static pastFirstCall As Boolean = False 'This is
being Serialized!!!!!!!!!!
If Not pastFirstCall Then
mNextMessageNumber = mNextPersistableMessageNo
pastFirstCall = True
End If
NextMessageNo = mNextMessageNumber + 1
mNextMessageNumber = NextMessageNo
End Function
<NonSerialized()> Private mNextMessageNumber As Integer
Using Reflector, I can see that, internally, pastFirstCall is declared as a private
variable as:
Private $STATIC$NextMessageNo$2008$pastFirstCall As BooleanThe problem is that the
<NonSerialized> 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