2023-07-04 15:32:38 +02:00
|
|
|
include::../description.adoc[]
|
2023-05-25 14:18:12 +02:00
|
|
|
|
2023-07-04 15:32:38 +02:00
|
|
|
== How to fix it
|
2023-05-25 14:18:12 +02:00
|
|
|
|
2023-07-04 15:32:38 +02:00
|
|
|
=== Code examples
|
2023-05-25 14:18:12 +02:00
|
|
|
|
2023-07-04 15:32:38 +02:00
|
|
|
==== Noncompliant code example
|
2023-05-25 14:18:12 +02:00
|
|
|
|
2023-07-04 15:32:38 +02:00
|
|
|
[source,csharp,diff-id=1,diff-type=noncompliant]
|
2023-05-25 14:18:12 +02:00
|
|
|
----
|
|
|
|
[Serializable]
|
|
|
|
public class Foo
|
|
|
|
{
|
|
|
|
[OnSerializing]
|
2023-07-06 11:15:01 +02:00
|
|
|
public void OnSerializing(StreamingContext context) {} // Noncompliant: should be private
|
2023-05-25 14:18:12 +02:00
|
|
|
|
|
|
|
[OnSerialized]
|
2023-07-06 11:15:01 +02:00
|
|
|
int OnSerialized(StreamingContext context) {} // Noncompliant: should return void
|
2023-05-25 14:18:12 +02:00
|
|
|
|
|
|
|
[OnDeserializing]
|
2023-07-06 11:15:01 +02:00
|
|
|
void OnDeserializing() {} // Noncompliant: should have a single parameter of type StreamingContext
|
2023-05-25 14:18:12 +02:00
|
|
|
|
|
|
|
[OnSerializing]
|
2023-07-06 11:15:01 +02:00
|
|
|
public void OnSerializing2<T>(StreamingContext context) {} // Noncompliant: should have no type parameters
|
2023-05-25 14:18:12 +02:00
|
|
|
|
|
|
|
[OnDeserialized]
|
2023-07-06 11:15:01 +02:00
|
|
|
void OnDeserialized(StreamingContext context, string str) {} // Noncompliant: should have a single parameter of type StreamingContext
|
2023-05-25 14:18:12 +02:00
|
|
|
}
|
|
|
|
----
|
|
|
|
|
|
|
|
|
2023-07-04 15:32:38 +02:00
|
|
|
==== Compliant solution
|
2023-05-25 14:18:12 +02:00
|
|
|
|
2023-07-04 15:32:38 +02:00
|
|
|
[source,csharp,diff-id=1,diff-type=compliant]
|
2023-05-25 14:18:12 +02:00
|
|
|
----
|
|
|
|
[Serializable]
|
|
|
|
public class Foo
|
|
|
|
{
|
|
|
|
[OnSerializing]
|
|
|
|
private void OnSerializing(StreamingContext context) {}
|
|
|
|
|
|
|
|
[OnSerialized]
|
|
|
|
private void OnSerialized(StreamingContext context) {}
|
|
|
|
|
|
|
|
[OnDeserializing]
|
|
|
|
private void OnDeserializing(StreamingContext context) {}
|
|
|
|
|
|
|
|
[OnDeserialized]
|
|
|
|
private void OnDeserialized(StreamingContext context) {}
|
|
|
|
}
|
|
|
|
----
|
|
|
|
|
2023-07-04 15:32:38 +02:00
|
|
|
include::../resources.adoc[]
|
2021-06-02 20:44:38 +02:00
|
|
|
|
2021-06-03 09:05:38 +02:00
|
|
|
ifdef::env-github,rspecator-view[]
|
2021-09-20 15:38:42 +02:00
|
|
|
|
|
|
|
'''
|
|
|
|
== Implementation Specification
|
|
|
|
(visible only on this page)
|
|
|
|
|
2023-05-25 14:18:12 +02:00
|
|
|
=== Message
|
|
|
|
|
|
|
|
Make this method [non-public | non-static | return 'void' | have no type parameters | have a single parameter of type 'StreamingContext'].
|
|
|
|
|
2021-09-20 15:38:42 +02:00
|
|
|
|
|
|
|
include::../highlighting.adoc[]
|
|
|
|
|
2021-06-08 15:52:13 +02:00
|
|
|
'''
|
2021-06-02 20:44:38 +02:00
|
|
|
== Comments And Links
|
|
|
|
(visible only on this page)
|
|
|
|
|
|
|
|
include::../comments-and-links.adoc[]
|
2023-06-22 10:38:01 +02:00
|
|
|
|
2021-06-03 09:05:38 +02:00
|
|
|
endif::env-github,rspecator-view[]
|