1

I have a generic type:

public class Packet<T> where T : IContent
{
    private int id;
    public int Id { get { return this.id; } }

    private T content;
    public T Content { get { return this.content; } }
}

I want to deserialize/serialize instances of this type from/to XML. IContent is defined like that:

public interface IContent
{
    XmlSerializer Serializer{get;}
}

Basically, I would like the Packet to use the serializer provided by its content to serialize and deserialize its content member. This serializer is in fact an instance of a pre-compiled xml serializer generated by sgen.exe.

Is it possible without making Packet<T> implementing IXmlSerializable?

John Saunders
  • 160,644
  • 26
  • 247
  • 397
Romain Verdier
  • 12,833
  • 7
  • 57
  • 77

2 Answers2

1

Yes, you can implement a custom class directly with IXmlSerializable.
For more information, see this article.

Sachin Gaur
  • 12,909
  • 9
  • 33
  • 38
0

If you're using Generic Type, it is not able to generate a pre-completed XmlSerializer.

Brock Adams
  • 90,639
  • 22
  • 233
  • 295
Rock
  • 263
  • 1
  • 2
  • 10