rspec/rules/S3927/vbnet/rule.adoc

59 lines
1.9 KiB
Plaintext
Raw Normal View History

Serialization event handlers that don't have the correct signature will simply not be called, thus bypassing any attempts to augment the automated de/serialization.
2020-12-23 14:59:06 +01:00
This rule raises issue when a method marked with one of the following attributes is ``Public``, ``Shared``, is a ``Function`` not a ``Sub``, has type parameters, or does not have a single parameter of type ``System.Runtime.Serialization.StreamingContext``:
2020-12-23 14:59:06 +01:00
* ``System.Runtime.Serialization.OnSerializingAttribute``
* ``System.Runtime.Serialization.OnSerializedAttribute``
* ``System.Runtime.Serialization.OnDeserializingAttribute``
* ``System.Runtime.Serialization.OnDeserializedAttribute``
2020-06-30 12:48:39 +02:00
== Noncompliant Code Example
----
<Serializable>
Public Class Foo
<OnSerializing>
Public Sub OnSerializing(ByVal context As StreamingContext) ' Noncompliant should be private
End Sub
<OnSerialized>
Private Function OnSerialized(ByVal context As StreamingContext) As Integer ' Noncompliant should return void
End Function
<OnDeserializing>
Private Sub OnDeserializing() ' Noncompliant should have a single parameter of type StreamingContext
End Sub
<OnSerializing>
Public Sub OnSerializing2(Of T)(ByVal context As StreamingContext) ' Noncompliant should have no type parameters
End Sub
<OnDeserialized>
Private Sub OnDeserialized(ByVal context As StreamingContext, ByVal str As String) ' Noncompliant should have a single parameter of type StreamingContext
End Sub
End Class
----
== Compliant Solution
----
<Serializable>
Public Class Foo
<OnSerializing>
Private Sub OnSerializing(ByVal context As StreamingContext)
End Sub
<OnSerialized>
Private Sub OnSerialized(ByVal context As StreamingContext)
End Sub
<OnDeserializing>
Private Sub OnDeserializing(ByVal context As StreamingContext)
End Sub
<OnDeserialized>
Private Sub OnDeserialized(ByVal context As StreamingContext)
End Sub
End Class
----