
Inline adoc files when they are included exactly once. Also fix language tags because this inlining gives us better information on what language the code is written in.
84 lines
2.4 KiB
Plaintext
84 lines
2.4 KiB
Plaintext
== Why is this an issue?
|
|
|
|
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.
|
|
|
|
|
|
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++``:
|
|
|
|
* ``++System.Runtime.Serialization.OnSerializingAttribute++``
|
|
* ``++System.Runtime.Serialization.OnSerializedAttribute++``
|
|
* ``++System.Runtime.Serialization.OnDeserializingAttribute++``
|
|
* ``++System.Runtime.Serialization.OnDeserializedAttribute++``
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,vbnet]
|
|
----
|
|
<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
|
|
|
|
[source,vbnet]
|
|
----
|
|
<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
|
|
----
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
=== Message
|
|
|
|
Make this method [non-public | non-shared | a 'Sub' not a 'Function' | have no type parameters | have a single parameter of type 'StreamingContext'].
|
|
|
|
|
|
include::../highlighting.adoc[]
|
|
|
|
'''
|
|
== Comments And Links
|
|
(visible only on this page)
|
|
|
|
include::../comments-and-links.adoc[]
|
|
endif::env-github,rspecator-view[]
|