rspec/rules/S2552/csharp/rule.adoc

32 lines
858 B
Plaintext
Raw Normal View History

2021-04-28 16:49:39 +02:00
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) {
// ...
}
}
----