Daniel Peñalba
Daniel Peñalba

Reputation: 31887

XmlInclude attribute and derived classes

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.

Upvotes: 0

Views: 1974

Answers (1)

Rob Levine
Rob Levine

Reputation: 41328

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.

Upvotes: 2

Related Questions