rspec/rules/S3927/vbnet/rule.adoc

81 lines
2.3 KiB
Plaintext
Raw Normal View History

== 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.
2021-02-02 15:02:10 +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++``:
2021-01-27 13:42:22 +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
2020-06-30 12:48:39 +02:00
2022-02-04 17:28:24 +01:00
[source,vbnet]
2020-06-30 12:48:39 +02:00
----
<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
2020-06-30 12:48:39 +02:00
2022-02-04 17:28:24 +01:00
[source,vbnet]
2020-06-30 12:48:39 +02:00
----
<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)
include::message.adoc[]
include::../highlighting.adoc[]
'''
== Comments And Links
(visible only on this page)
include::../comments-and-links.adoc[]
endif::env-github,rspecator-view[]