これは、あなたの側でより多くの努力を必要とする、きめの細かい制御のケースだと思います。つまり、自動プロパティにはデフォルトでシリアル化可能なバッキング フィールドがあります。デフォルト以外が必要な場合は、自動プロパティを使用できません。
プロパティに対して使用するとうまくいくかもしれないと思っていまし[field:NonSerialized]
たが、うまくいきません。C# の仕様では、バッキング フィールドのシリアル化可能性について明示的に言及していませんが、これには含まれています (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; } }
}
したがって、バッキング フィールドはシリアライズ可能です (デフォルト)。