43 lines
1022 B
Plaintext
43 lines
1022 B
Plaintext
Classes that declare an implementation of ``++Serializable++`` should provide a serializable constructor. Without such a constructor, you'll be unable to deserialize the class.
|
|
|
|
|
|
Serialization constructors should be ``++private++`` for ``++sealed++`` types and ``++protected++`` otherwise.
|
|
|
|
|
|
== Noncompliant Code Example
|
|
|
|
----
|
|
[Serializable]
|
|
public class Person : ISerializable { // Noncompliant; missing serializable constructor
|
|
public void GetObjectData (SerializationInfo info, StreamingContext context) {
|
|
// ...
|
|
}
|
|
}
|
|
----
|
|
|
|
|
|
== Compliant Solution
|
|
|
|
----
|
|
[Serializable]
|
|
public class Person : ISerializable { // Noncompliant; missing serializable constructor
|
|
|
|
protected Person (SerializationInfo info, StreamingContext context) {
|
|
// ...
|
|
}
|
|
|
|
public void GetObjectData (SerializationInfo info, StreamingContext context) {
|
|
// ...
|
|
}
|
|
}
|
|
----
|
|
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
'''
|
|
== Comments And Links
|
|
(visible only on this page)
|
|
|
|
include::comments-and-links.adoc[]
|
|
endif::env-github,rspecator-view[]
|