I think this is a case of fine-grained control that requires more effort on your part. In other words, the automatic property will have a serializable support field by default. If you want nothing but the default, then you cannot use the automatic property.
I thought using [field:NonSerialized] against a property might work, but it is not. The C # specification does not explicitly cause the support field to be serializable, but it includes this (10.7.3):
The following example: public class Point { public int X { get; set; } // automatically implemented public int Y { get; set; } // automatically implemented } is equivalent to the following declaration: public class Point { private int x; private int y; public int X { get { return x; } set { x = value; } } public int Y { get { return y; } set { y = value; } } }
Thus, the support field is serializable (default).
Kent boogaart
source share