I'm using Xml serialization to persist some objects on disk.
The class structure is the following:
XmlInclude(typeof(BranchExplorerViewInfo))
public class ViewInfo
{
...
}
public class BranchExplorerViewInfo : ViewInfo
{
...
}
public class CustomBranchExplorerViewInfo: BranchExplorerViewInfo
{
...
}
Then, I need the following behavior:
BranchExplorerViewInfo view = new BranchExplorerViewInfo();
view.GetType().IsSerializable; //I need this to be TRUE
CustomBranchExplorerViewInfo customView = new CustomBranchExplorerViewInfo();
customView.GetType().IsSerializable; //I need this to be FALSE
So, I want BranchExplorerViewInfo
to be serializable but CustomBranchExplorerViewInfo
to be non-serializable. Is there any attribute to exclude a type/class?
Thanks in advance.
You are confusing two totally different types of serialization.
On the one hand you are talking about [XmlInclude]
which is related to xml serialization.
On the other hand you are testing Type.IsSerializable
which is related to binary serialization (ie related to the [Serializable]
attribute, and the BinaryFormatter
class).
Although these are both types of serialization, they are very different and unrelated.
There isn't any simple equivalent test of "IsXmlSerialization" that I can think of.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.