CA2229 Rules with a Model

71 views Asked by At

I was doing Code Analysis on my project and I got some warning on rule CA2229

Considering this snippet

[Serializable]
public partial class Split : ModelBase
{
    private double? fx;

    public int? Currency { get; set; }

    public double? Fx
    {
        get
        {
            return this.fx;
        }
        set
        {
            this.fx = value;
            RaisePropertyChanged(() => Fx);

        }
    }
}

should I implenent the constructor as suggested?

protected Split(SerializationInfo info, StreamingContext context)
{

 }

Thanks

1

There are 1 answers

1
Geert van Horrik On BEST ANSWER

Note that the serializable part is only required when using binary serialization. In that case it's best to create 2 constructors:

public Split()
{
    // Use when instantiating yourself
}

public Split(SerializationInfo info, StreamingContext context)
{
    // Used by serialization
}