XmlSerializer, sgen.exe and generics

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 as follows:

public interface IContent
{
    XmlSerializer Serializer{get;}
}

      

Basically, I would like to be able to Packet

use the serializer provided by its content to serialize and deserialize its content. This serializer is actually an instance of the precompiled XML serializer generated by sgen.exe.

Is this possible if you don't do the Packet<T>

implementation IXmlSerializable

?

+1


source to share


2 answers


Yes, you can implement your own class directly using IXmlSerializable.
For more information, see this article.



+1


source


If you are using Generic Type it cannot create pre-populated XmlSerializer.



0


source







All Articles