
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.
72 lines
1.8 KiB
Plaintext
72 lines
1.8 KiB
Plaintext
== Why is this an issue?
|
|
|
|
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
|
|
|
|
[source,csharp]
|
|
----
|
|
[Serializable]
|
|
public class Person : ISerializable { // Noncompliant; missing serializable constructor
|
|
public void GetObjectData (SerializationInfo info, StreamingContext context) {
|
|
// ...
|
|
}
|
|
}
|
|
----
|
|
|
|
|
|
=== Compliant solution
|
|
|
|
[source,csharp]
|
|
----
|
|
[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[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
=== Message
|
|
|
|
Add a serialization constructor to this class.
|
|
|
|
|
|
'''
|
|
== Comments And Links
|
|
(visible only on this page)
|
|
|
|
=== on 4 Feb 2015, 14:09:09 Ann Campbell wrote:
|
|
Gendarme MissingSerializationConstructorRule
|
|
|
|
=== on 13 Apr 2015, 10:48:15 Freddy Mallet wrote:
|
|
@Tamas, does this rule makes sense to you ? Thanks
|
|
|
|
=== on 22 May 2015, 09:21:46 Tamas Vajk wrote:
|
|
\[~freddy.mallet] Yes, it makes sense. BUT it is already implemented by the Roslyn team:
|
|
|
|
https://msdn.microsoft.com/en-us/library/ms182343.aspx
|
|
|
|
https://github.com/dotnet/roslyn/blob/master/src/Diagnostics/FxCop/Core/Usage/SerializationRulesDiagnosticAnalyzer.cs
|
|
|
|
=== on 28 May 2015, 12:44:12 Tamas Vajk wrote:
|
|
This rule duplicates CA2229 (\https://msdn.microsoft.com/en-us/library/ms182343.aspx), which is already implemented by the Roslyn team.
|
|
|
|
endif::env-github,rspecator-view[]
|