XmlSerializerFactory

I would like to reuse the XmlSerializer for a class type. Currently, I create a static copy of the XmlSerializer. Recently, I found the XmlSerializerFactory class in the .net 2.0. It seems a good class to use to create xmlserializer. But, the documents said " This class supports the .NET Framework infrastructure and is not intended to be used directly from your code."

So my question is: should I use XmlSerializerFactory to create XmlSerializer Is it thread safe Do XmlSerializerFactory cache the XmlSerializer it creates, so every time I call Create method, the XmlSerializerFactory do not recreate the XmlSerializer

Thank you very much



Answer this question

XmlSerializerFactory

  • hessie

    Just use the constructor for the XmlSerializer and keep a reference to it if you are going to reuse it.

    If you are in a position where you can’t keep a reference to it you should make a static class that can hold it. Like:

    public static class XmlSerializer<T>

    {

    public static XmlSerializer

    Serializer = new XmlSerializer(typeof(T));

    }



  • XmlSerializerFactory