MSDN官方XmlSerializer类使用说明链接:
http://msdn.microsoft.com/zh-CN/library/system.xml.serialization.xmlserializer(v=VS.100).aspx

动态生成的程序集

仅当使用以下构造函数时,才会发生此行为:

XmlSerializer.XmlSerializer(Type)

XmlSerializer.XmlSerializer(Type, String)

Hashtable 中缓存程序集,如下面的示例所示。

 
Hashtable serializers = new Hashtable();

// Use the constructor that takes a type and XmlRootAttribute.
XmlSerializer s = new XmlSerializer(typeof(MyClass), myRoot);

// Implement a method named GenerateKey that creates unique keys 
// for each instance of the XmlSerializer. The code should take 
// into account all parameters passed to the XmlSerializer 
// constructor.
object key = GenerateKey(typeof(MyClass), myRoot);

// Check the local cache for a matching serializer.
XmlSerializer ser = (XmlSerializer)serializers[key];
if (ser == null) 
{
    ser = new XmlSerializer(typeof(MyClass), myRoot);
    // Cache the serializer.
    serializers[key] = ser;
}
else
{
    // Use the serializer to serialize, or deserialize.
}


相关文章:

  • 2022-01-11
  • 2022-12-23
  • 2022-12-23
  • 2021-10-16
  • 2022-12-23
  • 2021-06-14
  • 2022-01-22
  • 2022-12-23
猜你喜欢
  • 2021-11-02
  • 2021-08-22
  • 2021-11-20
  • 2021-11-04
  • 2022-12-23
  • 2022-12-23
  • 2021-07-06
相关资源
相似解决方案