I have a class definition like this:
[Serializable]
public class MyDictionary: Dictionary<string, object>
{
}
However, I get this Code Analysis warning:
CA2229 Implement serialization constructors Add a constructor to TcpFieldValueDictionary with the following signature: 'protected TcpFieldValueDictionary(SerializationInfo info, StreamingContext context)'.
However, the generic dictionary already has the constructor, only with a public
modifier.
It is easy to add this constructor (see below), but why should this be done? What is the advantage?
protected MyDictionary(SerializationInfo info, StreamingContext context)
: base(info, context)
{ }
Constructors aren't inherited. It doesn't matter what constructors your base type has - if you want a constructor with a particular signature for your class, you have to implement one.
Otherwise, you just get the default parameterless constructor.