2023-05-03 11:06:20 +02:00
== Why is this an issue?
2021-06-08 14:23:48 +02:00
The ``++ISerializable++`` interface gives you control over _how_ your class is serialized, but does not itself make the class serializable. Such classes must also have the ``++[Serializable]++`` attribute.
2023-05-03 11:06:20 +02:00
=== Noncompliant code example
2021-06-08 14:23:48 +02:00
2022-02-04 17:28:24 +01:00
[source,csharp]
2021-06-08 14:23:48 +02:00
----
public class Person : ISerializable { // Noncompliant; [Serializable] attribute missing
// ...
}
----
2023-05-03 11:06:20 +02:00
=== Compliant solution
2021-06-08 14:23:48 +02:00
2022-02-04 17:28:24 +01:00
[source,csharp]
2021-06-08 14:23:48 +02:00
----
[Serializable]
public class Person : ISerializable {
// ...
}
----
ifdef::env-github,rspecator-view[]
2021-06-08 15:52:13 +02:00
'''
2021-06-08 14:23:48 +02:00
== Comments And Links
(visible only on this page)
2023-05-25 14:18:12 +02:00
=== on 4 Feb 2015, 14:17:17 Ann Campbell wrote:
Gendarme MissingSerializableAttributeOnISerializableTypeRule
=== on 13 Apr 2015, 10:47:40 Freddy Mallet wrote:
@Tamas, does this rule makes sense to you ? Thanks
=== on 22 May 2015, 09:23:53 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/ms182350.aspx
https://github.com/dotnet/roslyn/blob/master/src/Diagnostics/FxCop/Core/Usage/SerializationRulesDiagnosticAnalyzer.cs
=== on 28 May 2015, 12:44:55 Tamas Vajk wrote:
This rule duplicates CA2237 (\https://msdn.microsoft.com/en-us/library/ms182350.aspx), which is already implemented by the Roslyn team.
2021-06-08 14:23:48 +02:00
endif::env-github,rspecator-view[]