Given a class marked as [Serializable]
, how to we know whether the member of it will be serialized or not (the member has no attribute) by XmlSerializer
?
For example:
[Serializable]
public class C2
{
public int x1 = 1;
private int x2 = 2;
public static int x3 = 3;
public readonly int x4 = 4;
public int Y1 { get; set; }
public static int Y2 { get; set; }
}
We have a class C2
, and after serialized a new object C2 c = new C2()
into XML string, I found that only x1
and Y1
are serialized. So I infer that:
public
field and property will be serialized.private
field and property will not be serialized.static
andreadonly
field and property will not be serialzed.- MethodInfo will not be serialized.
- ...
My question is that is there any guidelines to know that: without marking any attribute to a member of class, how do we know that this member will be serialized or not?